I'm learning about monads and have a few questions.
This is where I am right now. Please correct me where I am wrong.
The
>>=symbol is an infix operator. Infix operators are functions that take two arguments (left-hand side and right-hand side) and return a value.The
>>=symbol is called the bind operator and has signatureMonad m => m t -> (t -> m u) -> m u. However, the types don't seem to line up here. We get a value of typem tand the second argument is a function that takes at. (I don't see how to connect the dots.)This must mean that the bind function is somehow able to remove the
mfrom them tin order to get thetand pass it to the function.
Here are my questions:
Is the ability to remove the
mfromm tsomething that is only possible inside such a bind operator. Does this bind operator have some special priviliges or something?What does it have to do with state changes? I understand (I think) that the goal of monads is to 'wrap' side-effects so that they are isolated from the rest of the program. But what is the role of the bind operator in this?