The Semiring
class is for types that support an addition and multiplication operation.
Instances must satisfy the following laws:
(a + b) + c <-> a + (b + c)
zero + a = a + zero <-> a
a + b <-> b + a
(a * b) * c <-> a * (b * c)
one * a <-> a * one <-> a
a * (b + c) <-> (a * b) + (a * c)
(a + b) * c <-> (a * c) + (b * c)
zero * a <-> a * zero <-> zero
Note: The number
type is not fully law abiding members of this class hierarchy due to the potential
for arithmetic overflows, and the presence of NaN
and Infinity
values. The behaviour is
unspecified in these cases.
Added in v2.0.0
Signature
export declare function getFunctionSemiring<A, B>(S: Semiring<B>): Semiring<(a: A) => B>
Added in v2.0.0
Signature
export interface Semiring<A> {
readonly add: (x: A, y: A) => A
readonly zero: A
readonly mul: (x: A, y: A) => A
readonly one: A
}
Added in v2.0.0