linear-base-0.1.0: Standard library for linear types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Num and sub-classes

class (Ring a, FromInteger a) => Num a where Source #

Methods

abs :: a %1 -> a Source #

signum :: a %1 -> a Source #

Instances

Instances details
Num Double Source # 
Instance details

Defined in Data.Num.Linear

Methods

abs :: Double %1 -> Double Source #

signum :: Double %1 -> Double Source #

Num Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

abs :: Int %1 -> Int Source #

signum :: Int %1 -> Int 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

Methods

(+) :: a %1 -> a %1 -> a Source #

Instances

Instances details
Additive Double Source # 
Instance details

Defined in Data.Num.Linear

Methods

(+) :: Double %1 -> Double %1 -> Double Source #

Additive Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

(+) :: Int %1 -> Int %1 -> Int Source #

class Additive a => AddIdentity a where Source #

An Additive type with an identity on (+).

Methods

zero :: a Source #

Instances

Instances details
AddIdentity Double Source # 
Instance details

Defined in Data.Num.Linear

Methods

zero :: Double Source #

AddIdentity Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

zero :: Int Source #

class AddIdentity a => AdditiveGroup a where Source #

An AddIdentity with inverses that satisfies the laws of an abelian group

Minimal complete definition

negate | (-)

Methods

negate :: a %1 -> a Source #

(-) :: a %1 -> a %1 -> a Source #

Instances

Instances details
AdditiveGroup Double Source # 
Instance details

Defined in Data.Num.Linear

Methods

negate :: Double %1 -> Double Source #

(-) :: Double %1 -> Double %1 -> Double Source #

AdditiveGroup Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

negate :: Int %1 -> Int Source #

(-) :: Int %1 -> Int %1 -> Int Source #

class Multiplicative a where Source #

A numeric type with an associative (*) operation

Methods

(*) :: a %1 -> a %1 -> a Source #

Instances

Instances details
Multiplicative Double Source # 
Instance details

Defined in Data.Num.Linear

Methods

(*) :: Double %1 -> Double %1 -> Double Source #

Multiplicative Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

(*) :: Int %1 -> Int %1 -> Int Source #

class Multiplicative a => MultIdentity a where Source #

A Multipcative type with an identity for (*)

Methods

one :: a Source #

Instances

Instances details
MultIdentity Double Source # 
Instance details

Defined in Data.Num.Linear

Methods

one :: Double Source #

MultIdentity Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

one :: Int Source #

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

Instances details
Semiring Double Source # 
Instance details

Defined in Data.Num.Linear

Semiring Int Source # 
Instance details

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

Instances details
Ring Double Source # 
Instance details

Defined in Data.Num.Linear

Ring Int Source # 
Instance details

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

Instances details
FromInteger Double Source # 
Instance details

Defined in Data.Num.Linear

FromInteger Int Source # 
Instance details

Defined in Data.Num.Linear

Methods

fromInteger :: Integer %1 -> Int Source #

Mechanisms for deriving instances

newtype Adding a Source #

Constructors

Adding a 

Instances

Instances details
Additive a => Semigroup (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

(<>) :: Adding a -> Adding a -> Adding a #

sconcat :: NonEmpty (Adding a) -> Adding a #

stimes :: Integral b => b -> Adding a -> Adding a #

AddIdentity a => Monoid (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

mempty :: Adding a #

mappend :: Adding a -> Adding a -> Adding a #

mconcat :: [Adding a] -> Adding a #

Additive a => Semigroup (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

(<>) :: Adding a %1 -> Adding a %1 -> Adding a Source #

AddIdentity a => Monoid (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

mempty :: Adding a Source #

getAdded :: Adding a %1 -> a Source #

newtype Multiplying a Source #

Constructors

Multiplying a 

Instances

Instances details
Multiplicative a => Semigroup (Multiplying a) Source # 
Instance details

Defined in Data.Num.Linear

MultIdentity a => Monoid (Multiplying a) Source # 
Instance details

Defined in Data.Num.Linear

Multiplicative a => Semigroup (Multiplying a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

(<>) :: Multiplying a %1 -> Multiplying a %1 -> Multiplying a Source #

MultIdentity a => Monoid (Multiplying a) Source # 
Instance details

Defined in Data.Num.Linear