categorical-algebra-0.0.0.1: Categorical Monoids and Semirings

Data.Semiring

Description

Categorical semirings (my term, but maybe the correct one) are an alternative to Arrows, but play nicely with groupoids. | See the source or the latex source for more background.

Synopsis

# Endofunctors for construction

class Category k => Ctor k constr | constr -> k whereSource

An endofunctor for combining two morphisms|

Methods

selfmap :: k a b -> k c d -> k (constr a c) (constr b d)Source

Instances

 Ctor (->) Product Ctor (->) Sum Ctor Biject BProduct Ctor Biject BSum Monad m => Ctor (Kleisli m) KProduct Monad m => Ctor (Kleisli m) KSum Monad m => Ctor (KBiject m) KBProduct Monad m => Ctor (KBiject m) KBSum

## first/right like functions

promote :: Ctor k op => k a b -> k (op a c) (op b c)Source

construct a new morphism with identity|

swap_promote :: Ctor k op => k a b -> k (op c a) (op c b)Source

construct a new morphism with identity with the arguments reversed|

# Laws (Axioms) for building algebraic structures

class Ctor k op => Absorbs k op id | op -> k, op -> id whereSource

The absorbtion law => x+0 <-> x |

Methods

absorb :: k (op id a) aSource

unabsorb :: k a (op id a)Source

Instances

 Absorbs (->) Product One Absorbs (->) Sum Zero Absorbs Biject BProduct BOne Absorbs Biject BSum BZero Monad m => Absorbs (Kleisli m) KProduct KOne Monad m => Absorbs (Kleisli m) KSum KZero Monad m => Absorbs (KBiject m) KBProduct KBOne Monad m => Absorbs (KBiject m) KBSum KBZero

class Ctor k op => Assocative k op | op -> k whereSource

The assocative law => (x + y) + z <-> x + (y + z)|

Methods

assoc :: k (op (op a b) c) (op a (op b c))Source

unassoc :: k (op a (op b c)) (op (op a b) c)Source

Instances

 Assocative (->) Product Assocative (->) Sum Assocative Biject BProduct Assocative Biject BSum Monad m => Assocative (Kleisli m) KProduct Monad m => Assocative (Kleisli m) KSum Monad m => Assocative (KBiject m) KBProduct Monad m => Assocative (KBiject m) KBSum

class Ctor k op => Commutative k op | op -> k whereSource

The commutative law => x + y <-> y + x|

Methods

commute :: k (op a b) (op b a)Source

Instances

 Commutative (->) Product Commutative (->) Sum Commutative Biject BProduct Commutative Biject BSum Monad m => Commutative (Kleisli m) KProduct Monad m => Commutative (Kleisli m) KSum Monad m => Commutative (KBiject m) KBProduct Monad m => Commutative (KBiject m) KBSum

class Ctor k op => Annihilates k op zero | op zero -> k whereSource

The annihilation law => 0 * x <-> 0|

Methods

annihilates :: k (op zero a) zeroSource

Instances

 Annihilates (->) Product Zero Annihilates Biject BProduct BZero Monad m => Annihilates (Kleisli m) KProduct KZero Monad m => Annihilates (KBiject m) KBProduct KBZero

class (Ctor k add, Ctor k multi) => Distributes k add multi | add multi -> k whereSource

The distribution law => (a + b) * c <-> (a * c) + (b * c)|

Methods

distribute :: k (multi (add a b) c) (add (multi a c) (multi b c))Source

undistribute :: k (add (multi a c) (multi b c)) (multi (add a b) c)Source

Instances

 Distributes (->) Sum Product Distributes Biject BSum BProduct Monad m => Distributes (Kleisli m) KSum KProduct Monad m => Distributes (KBiject m) KBSum KBProduct

# Categorical Algebraic Structures

class (Assocative k dot, Absorbs k dot id) => Monoidial k dot id | dot id -> kSource

Monoidial Category class|

Instances

 Monoidial (->) Product One Monoidial (->) Sum Zero Monoidial Biject BProduct BOne Monoidial Biject BSum BZero Monad m => Monoidial (Kleisli m) KProduct KOne Monad m => Monoidial (Kleisli m) KSum KZero Monad m => Monoidial (KBiject m) KBProduct KBOne Monad m => Monoidial (KBiject m) KBSum KBZero

class (Monoidial k dot id, Commutative k dot) => CommutativeMonoidial k dot id | dot id -> kSource

Commutative Monoidial Category class|

Instances

 CommutativeMonoidial (->) Product One CommutativeMonoidial (->) Sum Zero CommutativeMonoidial Biject BProduct BOne CommutativeMonoidial Biject BSum BZero Monad m => CommutativeMonoidial (Kleisli m) KProduct KOne Monad m => CommutativeMonoidial (Kleisli m) KSum KZero Monad m => CommutativeMonoidial (KBiject m) KBProduct KBOne Monad m => CommutativeMonoidial (KBiject m) KBSum KBZero

class (CommutativeMonoidial k add zero, CommutativeMonoidial k multi one, Annihilates k multi zero, Distributes k add multi) => Semiring k add zero multi one | add zero multi one -> kSource

Semiring Category class|

Instances

 Semiring (->) Sum Zero Product One Semiring Biject BSum BZero BProduct BOne Monad m => Semiring (Kleisli m) KSum KZero KProduct KOne Monad m => Semiring (KBiject m) KBSum KBZero KBProduct KBOne

# Arrow like functions for semiring categories

first :: Semiring a add zero multi one => a b c -> a (multi b d) (multi c d)Source

Apply the multi monoid operator to the morphism and identity|

second :: Semiring a add zero multi one => a b c -> a (multi d b) (multi d c)Source

Apply the multi monoid operator to identity and the morphism|

left :: Semiring a add zero multi one => a b c -> a (add b d) (add c d)Source

Apply the add monoid operator to the morphism and identity|

right :: Semiring a add zero multi one => a b c -> a (add d b) (add d c)Source

Apply the add monoid operator to identity and the morphism|

# A groupoid class that is a category. Maybe this is a bad idea?

class Category g => Groupoid g whereSource

Methods

inv :: g a b -> g b aSource

Instances

 Category k => Groupoid (Iso k)

data Iso k a b Source

Constructors

 Iso Fieldsembed :: k a b project :: k b a

Instances

# Alegraic laws as isomorphism for groupoid instances

biject_sum_absorb :: Biject (BSum BZero a) aSource

biject_sum_assoc :: Biject (BSum (BSum a b) c) (BSum a (BSum b c))Source

biject_product_absorb :: Biject (BProduct BOne a) aSource

biject_product_assoc :: Biject (BProduct (BProduct a b) c) (BProduct a (BProduct b c))Source

biject_distributes :: Biject (BProduct (BSum a b) c) (BSum (BProduct a c) (BProduct b c))Source

kbiject_sum_absorb :: Monad m => KBiject m (KBSum KBZero a) aSource

kbiject_sum_assoc :: Monad m => KBiject m (KBSum (KBSum a b) c) (KBSum a (KBSum b c))Source

kbiject_product_absorb :: Monad m => KBiject m (KBProduct KBOne a) aSource

kbiject_product_assoc :: Monad m => KBiject m (KBProduct (KBProduct a b) c) (KBProduct a (KBProduct b c))Source

kbiject_distributes :: Monad m => KBiject m (KBProduct (KBSum a b) c) (KBSum (KBProduct a c) (KBProduct b c))Source