|
|
|
|
|
by ashton314
2390 days ago
|
|
This was the first time I've seen the "A monad over a category C is a triple (T,η,µ)" in a definition. That confirmed some mental models that I was a little unsure about. I'm new to the fp scene; still trying to get a good foundational understanding. |
|
The category-theoretic definition basically states that a monad is an endofunctor T equipped with two operations, return :: a -> T a and join :: T (T a) -> T a. T being a endofunctor just means that it is "mappable," AKA it has a function fmap :: (a -> b) -> T a -> T b that "lifts" functions into the type.
Monads capture the idea of flattening. If fmap changes the "contents" while preserving the "shape," join collapses nested layers to change the "shape."
Instead of join, the Haskell typeclasses (and this article) uses another function called bind, or >>=. You can derive join from >>=, and you can derive >>= from join and fmap. For lists, a more familiar name for >>= might be flatmap.