HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

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

Num and sub-classes

9 declarations
classclass (Ring a, FromInteger a) => Num a where
#

Methods

Instances3Num
  • Num DoubleDefined in linear-base-0.4.0 · Data.Num.Linear
  • Num IntDefined in linear-base-0.4.0 · Data.Num.Linear
  • (Movable a, Num a) => Num (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
classclass Additive a where
#

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 -> ainfixl 6
Instances3Additive
classclass (AddIdentity a, MultIdentity a) => Semiring a
#

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)
Instances3Semiring
classclass (AdditiveGroup a, Semiring a) => Ring a
#

A Ring instance is a numeric type with (+), (-), (*) and all the following properties: a group with (+) and a MultIdentity with (*) along with distributive laws.

Instances3Ring
  • Ring DoubleDefined in linear-base-0.4.0 · Data.Num.Linear
  • Ring IntDefined in linear-base-0.4.0 · Data.Num.Linear
  • (Movable a, Num a) => Ring (MovableNum a)Defined in linear-base-0.4.0 · Data.Num.Linear
classclass FromInteger a where
#

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

Instances3FromInteger

Mechanisms for deriving instances

4 declarations
newtypenewtype Adding a
#

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

Instances7Eq, Ord, Show, Monoid, Semigroup, …
valuegetAdded :: Adding a %1 -> a
#

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

newtypenewtype Multiplying a
#

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

Instances7Eq, Ord, Show, Monoid, Semigroup, …

Orphan instances

4 instances