3 ms·
First, all functors in Haskell are endofunctors in Hask. They map Haskell types to other Haskell types, and Haskell functions to other Haskell functions. A fu
by dllthomas 12y ago
First, all functors in Haskell are endofunctors in Hask. They map Haskell types to other Haskell types, and Haskell functions to other Haskell functions.
A functor in Category Theory has two parts - a map of the objects and a map of the arrows. In Haskell, when you create a Functor instance, you are saying "this type constructor is the map for objects; here's how you map the arrows".
It's typically not the best place to start, but since you asked - a monad, in category theory, is a functor plus two natural transformations. In Haskell, the functor is the type constructor plus fmap from the Functor instance. The natural transformations are return (eta, in the math) and join (mu). Haskell programmers have historically found it more useful to talk about bind than join, but in the presence of fmap you can implement either from the other, so there's not much theoretical difference:
join m = bind m id
bind m f = join (fmap f m)
- bsaul 12y agoThanks for that answer. I first thought monads were a completely different beast than functors, but considering the small number of fundamental objects category theory deals with, i had a hard time finding out what.