# BM Category Theory 5: Coproducts = Sum types

5.1 Coproducts = Sum types

Product c is the “Best” than any others like c’, with projections p, q into a and b respectively (Haskell “fst“, “snd“) — because all c’ = c (up to a unique isomorphism m).

Coproduct is like “yin-yang” (阴阳合一) sum of 2 objects {a, b} into c – injection “discriminately” (in Haskell by “Left” and “Right”)

5.2 Algebraic Data Types

Prove that Product and Sum are Monoids ? They are!

• Both are Associative.
• Identity for Product = Unit ()
• Identity for Sum  = Void

Product (*) , Sum (+) are Distributive :

$a * (b + c ) = a * b + a * c \iff (a , (Either \: b \: c)) = Either \: (a, b) \:( a, c)$

There is is no inverse for “sum”, or negative.

Hence, it is a  structure  Ring without “n” = Rig (or Semi-Ring)

Maybe (= 1+a)

data Maybe = Nothing | Just a

$\boxed {\text {Maybe } a = \text {Either () } a}$

Algebraic Data Types:

We can solve algebraic equation with Product & Sum :