3 ms·
It also doesn't help that that definition removes pretty much every aspect of what makes a monad a monad. It also deviates quite a bit from the mathematical def
by contravariant 5y ago
It also doesn't help that that definition removes pretty much every aspect of what makes a monad a monad. It also deviates quite a bit from the mathematical definition.
A definition like:
bind f (x:xs) = f(x)
would fit this type signature, but would very much not be a monad.
What makes a monad a monad is that it is a functor (so a special parametrized type of sorts) with
- a function to wrap a single value (wrap :: a -> M a)
- a function that can flatten nested versions (flatten :: M M a -> M a)
- such that wrapping twice and flattening is the same as wrapping once
- such that when flattening a triply nested structure it doesn't matter which level you flatten first.
And of course it also needs to satisfy the functor axioms, which are also frequently overlooked, though they're not too difficult they just mean that 'fmap' needs to play nice with identity functions and function composition.
And Haskell in particular suffers quite a bit from the fact that currying is a first class concept, while in category theory this is reserved for a rather special class of categories. This means that using functors in combination with functions of multiple arguments suddenly requires you to think about how to evaluate a tree of functions on a tree of values, where in most other languages you'd end up with a tree of tuples at worst. Granted you can do more if you solve those problems, but it requires you to think about concepts that even category theorists consider pretty 'out there'.