Modulelinear-base-0.4.0Haskell2010
Data.Num.Linear
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
- 2 types
- 9 classes
- 2 values
- Packagelinear-base-0.4.0
- Exports13
- LanguageHaskell2010
- LicenceMIT
- SourceLinear.hs
Num and sub-classes
9 declarationsA 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 + cMethods
(+) :: a %1 -> a %1 -> ainfixl 6
Instances3AddIdentity
AddIdentity DoubleDefined in linear-base-0.4.0 · Data.Num.LinearAddIdentity IntDefined in linear-base-0.4.0 · Data.Num.Linear(Movable a, Num a) => AddIdentity (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
An AddIdentity with inverses that satisfies the laws of an abelian group
Instances3AdditiveGroup
AdditiveGroup DoubleDefined in linear-base-0.4.0 · Data.Num.LinearAdditiveGroup IntDefined in linear-base-0.4.0 · Data.Num.Linear(Movable a, Num a) => AdditiveGroup (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
A numeric type with an associative (*) operation
Methods
(*) :: a %1 -> a %1 -> ainfixl 7
Instances3Multiplicative
Multiplicative DoubleDefined in linear-base-0.4.0 · Data.Num.LinearMultiplicative IntDefined in linear-base-0.4.0 · Data.Num.Linear(Movable a, Num a) => Multiplicative (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
A Multiplicative type with an identity for (*)
Methods
one :: a
Instances3MultIdentity
MultIdentity DoubleDefined in linear-base-0.4.0 · Data.Num.LinearMultIdentity IntDefined in linear-base-0.4.0 · Data.Num.Linear(Movable a, Num a) => MultIdentity (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
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)A Ring instance is a numeric type with (+), (-), (*) and all
the following properties: a group with (+) and a MultIdentity with (*)
along with distributive laws.
A numeric type that Integers can be embedded into while satisfying
all the typeclass laws Integers 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 xFor mathy folk: fromInteger should be a homomorphism over (+) and (*).
Methods
fromInteger :: Integer %1 -> a
Instances3FromInteger
FromInteger DoubleDefined in linear-base-0.4.0 · Data.Num.LinearFromInteger IntDefined in linear-base-0.4.0 · Data.Num.Linear(Movable a, Num a) => FromInteger (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
Mechanisms for deriving instances
4 declarationsA 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.
Constructors
Adding a
Instances7Eq, Ord, Show, Monoid, Semigroup, …
Eq a => Eq (Adding a)Defined in linear-base-0.4.0 · Data.Num.LinearOrd a => Ord (Adding a)Defined in linear-base-0.4.0 · Data.Num.LinearShow a => Show (Adding a)Defined in linear-base-0.4.0 · Data.Num.LinearAdditive a => Semigroup (Adding a)Defined in linear-base-0.4.0 · Data.Num.LinearAddIdentity a => Monoid (Adding a)Defined in linear-base-0.4.0 · Data.Num.LinearAddIdentity a => Monoid (Adding a)Defined in linear-base-0.4.0 · Data.Num.LinearAdditive a => Semigroup (Adding a)Defined in linear-base-0.4.0 · Data.Num.Linear
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.
Constructors
Instances7Eq, Ord, Show, Monoid, Semigroup, …
Eq a => Eq (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.LinearOrd a => Ord (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.LinearShow a => Show (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.LinearMultiplicative a => Semigroup (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.LinearMultIdentity a => Monoid (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.LinearMultIdentity a => Monoid (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.LinearMultiplicative a => Semigroup (Multiplying a)Defined in linear-base-0.4.0 · Data.Num.Linear
Orphan instances
4 instancesAddIdentity a => Monoid (Sum a)MultIdentity a => Monoid (Product a)Additive a => Semigroup (Sum a)Multiplicative a => Semigroup (Product a)