Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides a linear Num
class with instances.
Import this module to use linear versions of (+)
, (-)
, etc, on numeric
types like Int
and Double
.
The Typeclass Hierarchy
The Num
class is broken up into several instances. Here is the basic
hierarchy:
- Additive ⊆ AddIdentity ⊆ AdditiveGroup
- MultIdentity ⊆ MultIdentity
- (AddIdentity ∩ MultIdentity) ⊆ Semiring
- (AdditiveGroup ∩ Semiring) ⊆ Ring
- (FromInteger ∩ Ring) ⊆ Num
Synopsis
- class (Ring a, FromInteger a) => Num a where
- class Additive a where
- (+) :: a %1 -> a %1 -> a
- class Additive a => AddIdentity a where
- zero :: a
- class AddIdentity a => AdditiveGroup a where
- class Multiplicative a where
- (*) :: a %1 -> a %1 -> a
- class Multiplicative a => MultIdentity a where
- one :: a
- class (AddIdentity a, MultIdentity a) => Semiring a
- class (AdditiveGroup a, Semiring a) => Ring a
- class FromInteger a where
- fromInteger :: Integer %1 -> a
- newtype Adding a = Adding a
- getAdded :: Adding a %1 -> a
- newtype Multiplying a = Multiplying a
- getMultiplied :: Multiplying a %1 -> a
Num and sub-classes
class (Ring a, FromInteger a) => Num a where Source #
class Additive a where Source #
A type that can be added linearly. The operation (+)
is associative and
commutative, i.e., for all a
, b
, c
(a + b) + c = a + (b + c) a + b = b + c
class Additive a => AddIdentity a where Source #
An Additive
type with an identity on (+)
.
Instances
AddIdentity Double Source # | |
Defined in Data.Num.Linear | |
AddIdentity Int Source # | |
Defined in Data.Num.Linear |
class AddIdentity a => AdditiveGroup a where Source #
An AddIdentity
with inverses that satisfies
the laws of an abelian group
class Multiplicative a where Source #
A numeric type with an associative (*)
operation
class Multiplicative a => MultIdentity a where Source #
A Multiplicative
type with an identity for (*)
Instances
MultIdentity Double Source # | |
Defined in Data.Num.Linear | |
MultIdentity Int Source # | |
Defined in Data.Num.Linear |
class (AddIdentity a, MultIdentity a) => Semiring a Source #
A semiring class. This is basically a numeric type with mutliplication, addition and with identities for each. The laws:
zero * x = zero a * (b + c) = (a * b) + (a * c)
Instances
Semiring Double Source # | |
Defined in Data.Num.Linear | |
Semiring Int Source # | |
Defined in Data.Num.Linear |
class (AdditiveGroup a, Semiring a) => Ring a Source #
A Ring
instance is a numeric type with (+)
, (-)
, (*)
and all
the following properties: a group with (+)
and a MultIdentity
with (*)
along with distributive laws.
Instances
Ring Double Source # | |
Defined in Data.Num.Linear | |
Ring Int Source # | |
Defined in Data.Num.Linear |
class FromInteger a where Source #
A numeric type that Integer
s can be embedded into while satisfying
all the typeclass laws Integer
s obey. That is, if there's some property
like commutivity of integers x + y == y + x
, then we must have:
fromInteger x + fromInteger y == fromInteger y + fromInteger x
For mathy folk: fromInteger
should be a homomorphism over (+)
and (*)
.
fromInteger :: Integer %1 -> a Source #
Instances
FromInteger Double Source # | |
Defined in Data.Num.Linear fromInteger :: Integer %1 -> Double Source # | |
FromInteger Int Source # | |
Defined in Data.Num.Linear fromInteger :: Integer %1 -> Int Source # |
Mechanisms for deriving instances
A newtype wrapper to give the underlying monoid for an additive structure.
Deprecated because Sum
(reexported as
Sum
) now has a linear Semigroup
and
Monoid
instance.
Instances
AddIdentity a => Monoid (Adding a) Source # | |
Additive a => Semigroup (Adding a) Source # | |
Show a => Show (Adding a) Source # | |
Eq a => Eq (Adding a) Source # | |
Ord a => Ord (Adding a) Source # | |
Defined in Data.Num.Linear | |
AddIdentity a => Monoid (Adding a) Source # | |
Defined in Data.Num.Linear | |
Additive a => Semigroup (Adding a) Source # | |
newtype Multiplying a Source #
A newtype wrapper to give the underlying monoid for a multiplicative structure.
Deprecated because Product
(reexported as
Product
) now has a linear Semigroup
and
Monoid
instance.
Instances
getMultiplied :: Multiplying a %1 -> a Source #