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 signature- Monad m => m t -> (t -> m u) -> m u. However, the types don't seem to line up here. We get a value of type- m tand the second argument is a function that takes a- t. The types don't match.
- This must mean that the bind function is somehow able to remove the - mfrom the- m tin order to get the- tand pass it to the function.
Here are my questions:
- Is the ability to remove the - mfrom- m 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?