monad laws
All monads should follow (and in practice, all built-ins do), with respect to the above three operations,
- left identity
return a >>= k = k akwill be a function that accepsaand givesm a, so instead of wrappingato bind it to k, we should be able to apply.
- right identity
m >>= return = m- returning an "empty" monad should just give the monad instance itself
- associativity
(m a >>= f) >>= g = m a >>= (\x -> f x >>= g)- On the LHS;
fis of typea -> m b, so the first term ism bgis of typeb -> m c, result ism c
- On the RHS:
\x -> f ximmediately takes typeaand givesm b- bound to
gto givem c - in this sense, the bracket part is a lambda wrapper on simply
f >>= gthat allows it to be a function that fits thebindtypesig.
- On the LHS;