linear-base-0.2.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 infixl 6 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 infixl 6 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 infixl 7 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 Multiplicative 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 #

Deprecated: Use Sum (reexported as Sum) instead

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.

Constructors

Adding a

Deprecated: Use Sum (reexported as Sum) instead

Instances

Instances details
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 -> Adding a -> Adding a #

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

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

Show a => Show (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

showsPrec :: Int -> Adding a -> ShowS #

show :: Adding a -> String #

showList :: [Adding a] -> ShowS #

Eq a => Eq (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

(==) :: Adding a -> Adding a -> Bool #

(/=) :: Adding a -> Adding a -> Bool #

Ord a => Ord (Adding a) Source # 
Instance details

Defined in Data.Num.Linear

Methods

compare :: Adding a -> Adding a -> Ordering #

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

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

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

(>=) :: Adding a -> Adding a -> Bool #

max :: Adding a -> Adding a -> Adding a #

min :: Adding a -> Adding a -> Adding a #

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

Defined in Data.Num.Linear

Methods

mempty :: Adding a Source #

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

Defined in Data.Num.Linear

Methods

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

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

Deprecated: Use Sum (reexported as Sum) and pattern-match to extract the inner value linearly

newtype Multiplying a Source #

Deprecated: Use Product (reexported as Product) instead

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

Multiplying a

Deprecated: Use Product (reexported as Product) instead

Instances

Instances details
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

Show a => Show (Multiplying a) Source # 
Instance details

Defined in Data.Num.Linear

Eq a => Eq (Multiplying a) Source # 
Instance details

Defined in Data.Num.Linear

Ord a => Ord (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 #

getMultiplied :: Multiplying a %1 -> a Source #

Deprecated: Use Product (reexported as Product) and pattern-match to extract the inner value linearly

Orphan instances

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

Methods

mempty :: Product a Source #

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

Methods

mempty :: Sum a Source #

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

Methods

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

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

Methods

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