Given a endofunctor F: C -> C, an algebra is a pair (a, α) where a: Ob(C) and α: F a -> a.
An endofunctor can be though as a data structure with a type parameter F.
data F a = ...
Therefore, an algebra is a function:
a_alg :: F a -> a -- for some a
Quiz 1. Is a_alg
a natural transformation? Why?
Quiz 2. Give an example of an algebra, point out the functor
Given two F-algebra (a, α) and (b, β). A f-algebra homomorphism is a map f.
alpha F a -------> a | | | Ff | f v v F b -------> b beta
Here’s an example for Haskell. Let Maybe
functor.
strAlg :: Maybe String -> String
intAlg :: Maybe Int -> Int
f :: String -> Int
-- if for all x :: Maybe String, we have
intAlg (fmap f x) == f (strAlg x)
-- then f is a homomorphism.
Quiz: is length
function an f-algebra homomorphism? Show it!
Given an endofunctor
Quiz: what’s the identities on the objects in the category of F-algebras?
In some categories of f-algebras, there is a “best” algebra
in F i -------> i | | | | cata f v v F a -------> a f
The unique morphism from
data F a = Const
data F' a = Identity a
data F'' a = Zero | Succ a -- aka Maybe
data F''' a = Nil | Cons Int a
-- initial algebras
initF :: Const -> Const
initF = id
initF' :: Void -> Void
initF' = absurd
initF'' :: F'' Int -> Int
initF'' Zero = 0
initF'' Succ a = 1 + a
initF''' :: F''' [Int] -> [Int]
initF''' Nil = []
initF''' Cons x xs = (x:xs)
(Adámek’s algorithm)
https://ncatlab.org/nlab/show/initial+algebra+of+an+endofunctor#AdameksTheorem
the colimit of
Claim: If
Proof:
in F i -------> i | | | F m | m v v F F i -----> F i | F in | | F in | in v v F i -------> i
By initiality, i
has an unique morphism to i
, therefore in . m = id_i
.