| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Num.Linear
Description
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 Multipcative 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 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 x
For mathy folk: fromInteger should be a homomorphism over (+) and (*).
Methods
fromInteger :: Integer %1 -> a Source #
Instances
| FromInteger Double Source # | |
Defined in Data.Num.Linear Methods fromInteger :: Integer %1 -> Double Source # | |
| FromInteger Int Source # | |
Defined in Data.Num.Linear Methods fromInteger :: Integer %1 -> Int Source # | |
Mechanisms for deriving instances
Constructors
| Adding a |
newtype Multiplying a Source #
Constructors
| Multiplying a |
Instances
| Multiplicative a => Semigroup (Multiplying a) Source # | |
Defined in Data.Num.Linear Methods (<>) :: Multiplying a -> Multiplying a -> Multiplying a # sconcat :: NonEmpty (Multiplying a) -> Multiplying a # stimes :: Integral b => b -> Multiplying a -> Multiplying a # | |
| MultIdentity a => Monoid (Multiplying a) Source # | |
Defined in Data.Num.Linear Methods mempty :: Multiplying a # mappend :: Multiplying a -> Multiplying a -> Multiplying a # mconcat :: [Multiplying a] -> Multiplying a # | |
| Multiplicative a => Semigroup (Multiplying a) Source # | |
Defined in Data.Num.Linear Methods (<>) :: Multiplying a %1 -> Multiplying a %1 -> Multiplying a Source # | |
| MultIdentity a => Monoid (Multiplying a) Source # | |
Defined in Data.Num.Linear Methods mempty :: Multiplying a Source # | |
getMultiplied :: Multiplying a %1 -> a Source #