Module

Data.Ring

Package
purescript-prelude
Repository
purescript/purescript-prelude

#Ring Source

class (Semiring a) <= Ring a  where

The Ring class is for types that support addition, multiplication, and subtraction operations.

Instances must satisfy the following laws in addition to the Semiring laws:

  • Additive inverse: a - a = zero
  • Compatibility of sub and negate: a - b = a + (zero - b)

Members

  • sub :: a -> a -> a

Instances

#negate Source

negate :: forall a. Ring a => a -> a

negate x can be used as a shorthand for zero - x.

#(-) Source

Operator alias for Data.Ring.sub (left-associative / precedence 6)

#RingRecord Source

class RingRecord :: RowList Type -> Row Type -> Row Type -> Constraintclass (SemiringRecord rowlist row subrow) <= RingRecord rowlist row subrow | rowlist -> subrow where

A class for records where all fields have Ring instances, used to implement the Ring instance for records.

Members

Instances

Re-exports from Data.Semiring

#Semiring Source

class Semiring a  where

The Semiring class is for types that support an addition and multiplication operation.

Instances must satisfy the following laws:

  • Commutative monoid under addition:
    • Associativity: (a + b) + c = a + (b + c)
    • Identity: zero + a = a + zero = a
    • Commutative: a + b = b + a
  • Monoid under multiplication:
    • Associativity: (a * b) * c = a * (b * c)
    • Identity: one * a = a * one = a
  • Multiplication distributes over addition:
    • Left distributivity: a * (b + c) = (a * b) + (a * c)
    • Right distributivity: (a + b) * c = (a * c) + (b * c)
  • Annihilation: zero * a = a * zero = zero

Note: The Number and Int types are not fully law abiding members of this class hierarchy due to the potential for arithmetic overflows, and in the case of Number, the presence of NaN and Infinity values. The behaviour is unspecified in these cases.

Members

Instances

#SemiringRecord Source

class SemiringRecord :: RowList Type -> Row Type -> Row Type -> Constraintclass SemiringRecord rowlist row subrow | rowlist -> subrow

A class for records where all fields have Semiring instances, used to implement the Semiring instance for records.

Instances

#(+) Source

Operator alias for Data.Semiring.add (left-associative / precedence 6)

#(*) Source

Operator alias for Data.Semiring.mul (left-associative / precedence 7)