cat/algebra
Isomorphisms
(morphisms that are invertible) describing various equations.
Algebra on Types (Void = 0, Nil = 1, Bool = 2, Either(a, b) = a + b, Pair(a, b) = a * b, Maybe(a) = 1 + a)
Functions
pub fn alpha(p: Pair(a, Pair(b, c))) -> Pair(Pair(a, b), c)
Associativity up to isomorphism
of nested Pairs.
a * (b * c) = (a * b) * c
pub fn alpha_inv(p: Pair(Pair(a, b), c)) -> Pair(a, Pair(b, c))
Inverse associativity up to isomorphism
of nested Pairs.
(a * b) * c = a * (b * c)
pub fn beta(
e1: Either(a, Either(b, c)),
) -> Either(Either(a, b), c)
Associativity up to isomorphism
of nested Eithers.
a + (b + c) = (a + b) + c
pub fn beta_inv(
e1: Either(Either(a, b), c),
) -> Either(a, Either(b, c))
Inverse associativity up to isomorphism
of nested Eithers.
(a + b) + c = a + (b + c)
pub fn delta(e: Either(a, a)) -> Pair(Bool, a)
Morphism from Either(a, a)
to Pair(Bool, a)
.
a + a = 2 * a
pub fn delta_inv(p: Pair(Bool, a)) -> Either(a, a)
Morphism from Pair(Bool, a)
to Either(a, a)
.
2 * a = a + a
pub fn gamma(m: Maybe(a)) -> Either(Const(Nil, b), Identity(a))
Morphism from Maybe b
to Either (Const () a) (Identity b)
.
pub fn gamma_inv(
e: Either(Const(Nil, a), Identity(b)),
) -> Maybe(b)
Inverse morphism from Either (Const () a) (Idenity b)
to Maybe b
.
pub fn omega(m: Maybe(a)) -> Either(Nil, a)
Morphism from Maybe(a)
to Either(Nil, a)
.
1 + a
pub fn omega_inv(e: Either(Nil, a)) -> Maybe(a)
Inverse morphism from Either(Nil, a)
to Maybe(a)
.
1 + a
pub fn product_to_sum(
p: Pair(a, Either(b, c)),
) -> Either(Pair(a, b), Pair(a, c))
Distributivity up to isomorphism
.
a * (b + c) = a * b + a * c
pub fn psi_inv(x: a) -> Either(a, Void)
Inverse morphism from a
to Either(a, Void)
.
a = a + 0
pub fn sum_to_product(
e: Either(Pair(a, b), Pair(a, c)),
) -> Pair(a, Either(b, c))
Inverse distributivity up to isomorphism
.
a * b + a * c = a * (b + c)
pub fn swap(p: Pair(a, b)) -> Pair(b, a)
Commutativity up to isomorphism
for Pair.
a * b = b * a
Examples
swap(Pair(5, "abc"))
// -> Pair("abc", 5)