S.Albayrak Anasayfa Kategoriler

3.4 Haskell as category

Let us analyze Haskell from a category theory point of view. We will consider two categories:

C = {Int,Bool,Char} (3.5) D = {Double,Bool} (3.6)

where the objects are standard Haskell types. We can then write

End(Char) = Hom(Char,Char) = {toUpper,mirror,x ’a’,} (3.7) Aut(Char) = {mirror,} (3.8) Hom(Int,Bool) = {isLeapY ear,x x > 2,} (3.9)

For instance, the function f = (x x > 2) Hom(Int,Bool) is not an monomorphism, because

α = x if x is before k in alphabet 5 else 10 Hom(Char,Int) (3.10) α = x if x is before k in alphabet 7 else 12 Hom(Char,Int) (3.11)

even though αα, we have

f α = f α = x True (3.12)

however it is an epimorphism as for any βi Hom(Bool,Char) with

β(True) = b1,β(False) = b2 (3.13) β(True) = b1,β(False) = b2 (3.14) (3.15)

b1,b2,b1,b2 Char, we have

β f = x if x > 2 then b1, else b2 (3.16) β f = x if x > 2 then b1’, else b2’ (3.17)

hence ββ β.fβ f.

1    asd::VectorVector 
2    asd v = let sdf = asd^2 
3    in v \= 4 if True −− asd 
4    then asd = 2 
5    else f k 
6    where f x = x 2 "asdasd" 
7    % asd