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 :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s