The initial object is the object that has one and only one morphism going to any object in the category.

  • It’s okay to not have an initial object
  • However, even that doesn’t exist a guarantee the uniqueness of the initial object (if one exists) we can guarantee an uniqueness up to isomorphism.
    • An isomorphism is an invertible morphism; or a pair of morphisms, one being the inverse of the other.
    • Therefore any two initial objects are isomorphic.
      • the intuition you should have is that when two objects A and B are isomorphic they have the same relationship with other objects in the category. This is the sense in which they behave the same way, i. e. they can be reduced to be equal.
  • In the category of sets and functions, the initial object is the empty set.

https://statusfailed.com/blog/2019/04/25/what-does-unique-up-to-isomorphism-really-mean.html

The terminal object is the object with one and only one morphism coming to it from any object in the category.

  • And again, the terminal object is unique, up to isomorphism

You can’t help but to notice the symmetry between the way we defined the initial object and the terminal object. The only difference between the two was the direction of morphisms. It turns out that for any category C we can define the opposite category Cop just by reversing all the arrows.


Isomorphism

As programmers, we are well aware that defining equality is a non- trivial task. What does it mean for two objects to be equal? Do they have to occupy the same location in memory (pointer equality)? Or is it enough that the values of all their components are equal?

The intuition is that isomorphic objects look the same — they have the same shape. It means that every part of one object corresponds to some part of another object in a one-to-one mapping.

Mathematically it means that there is a mapping from object a to object b, and there is a mapping from object b back to object a, and they are the inverse of each other. In category theory we replace mappings with morphisms.

An isomorphism is an invertible morphism; or a pair of morphisms, one being the inverse of the other. We understand the inverse in terms of composition and identity: Morphism g is the inverse of morphism f if their composition is the identity morphism. These are actually two equations because there are two ways of composing two morphisms:

f . g = id 
g . f = id

When people say that the initial (terminal) object was unique up to isomorphism, they meant that any two initial (terminal) objects are isomorphic.


Products

We can think about Products as a “pair of values”. Like a Cartesian products.

  1. You get A from one category.
  2. You get B from another category.
  3. Finally you combine both in a pair, so the product is: (a, b)
  4. Now you also create two “mapping projections” that will extract the values.
    1. In Haskell, these are called fst, snd

So a product (sometimes also called as “Categorical Product”) is:

A product of two objects a and b is the object c equipped with two projections (p and q) such that for any other object c’ equipped with two projections there is a unique morphism m from c’ to c that factorizes those projections.

Let’s elaborate:

if C (the product of A and B) is:

p :: c -> a -- here 'p' is equal to 'fst' in haskell
q :: c -> b -- here 'q' is equal to 'snd' in haskell

And C’ is:

p' :: c' -> a
q' :: c' -> b

Then you have a unique morphism m :

m :: c' -> c

and this morphism can factorize the two projections:

p' = p . m
q' = q . m

This is important to do some ranking:

We want to be able to compare two instances of our pattern. We want to compare one candidate object *c* and its two projections *p* and *q* with another candidate object *c’* and its two projections *p’* and *q’*. We would like to say that *c* is “better” than *c’* if there is a morphism *m* from *c’* to *c* — but that’s too weak. We also want its projections to be “better,” or “more universal,” than the projections of *c’*. What it means is that the projections *p’*`` and *q’* can be reconstructed from p and q using m:

https://bartoszmilewski.com/2015/01/07/products-and-coproducts/

  • Not every category has products, and even if it has, maybe it doesn’t have for every pair of objects.
  • But if a category has products, then we can say that it is a “nice” category.
    • The category of sets is nice, because in the category of sets, every two sets, have a product.

A (higher order) function that produces the factorizing function m from two candidates is sometimes called the factorizer. In our case, it would be the function:

factorizer :: (c -> a) -> (c -> b) -> (c -> (a, b))
factorizer p q = \x -> (p x, q x)

Disclaimer:

The object P alone isn’t a product. The product consists of the object P and two morphisms pi1 and pi2.

Often these morphisms are clear from the context, and we simply say let A × B be the product of A and B without specifying the morphisms.

https://kavigupta.org/2016/05/08/Haskell-Classes-For-Products-And-Coproducts/


Coproduct (sum types)

Here is the diagram for product of two object in a category:

And here is the one for coproduct:

Notice that It means that the product (resp. coproduct) of two objects of a category 𝐶 is its coproduct (resp. product) in 𝐶op , the opposite category of 𝐶 .

https://stackoverflow.com/questions/56020174/understanding-the-diagrams-of-product-and-coproduct

In haskell, the definition of a Product would be:

data Either a b = Left a | Right b

And this basically means that you can:

  • build this type by calling the constructor ‘Left a’, and then your type will have an ‘a type
  • build this type by calling the constructor ‘Left b’, and then your type will have an ‘b type

These two constructors corresponds to the i1 and i2 from the diagram.

  • For example: If we are defining a coproduct in Java, we can represent our coproduct as a Class with two constructors to insert the values.

how can we deconstruct this value? Because the Either means that we can get an a or a b, so there must be a way to take in count both possibilities. The solution for this is called PATTERN MATCHING.



🌱 Back to Garden