Module

# Data.CommutativeRing

Package
purescript-prelude
Repository
purescript/purescript-prelude

### #CommutativeRingSource

``class (Ring a) <= CommutativeRing a ``

The `CommutativeRing` class is for rings where multiplication is commutative.

Instances must satisfy the following law in addition to the `Ring` laws:

• Commutative multiplication: `a * b = b * a`

#### Instances

• `CommutativeRing Int`
• `CommutativeRing Number`
• `CommutativeRing Unit`
• `(CommutativeRing b) => CommutativeRing (a -> b)`

## Re-exports from Data.Ring

### #RingSource

``class (Semiring a) <= Ring a ``

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

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

• Additive inverse: `a - a = (zero - a) + a = zero`

#### Instances

• `Ring Int`
• `Ring Number`
• `Ring Unit`
• `(Ring b) => Ring (a -> b)`

## Re-exports from Data.Semiring

### #SemiringSource

``class Semiring a  where``

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

Instances must satisfy the following laws:

• 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`
• 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

• `add :: a -> a -> a`
• `zero :: a`
• `mul :: a -> a -> a`
• `one :: a`

#### Instances

• `Semiring Int`
• `Semiring Number`
• `(Semiring b) => Semiring (a -> b)`
• `Semiring Unit`

### #(+)Source

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

### #(*)Source

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