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 t
and the second argument is a function that takes at
. The types don't match.This must mean that the bind function is somehow able to remove the
m
from them t
in order to get thet
and pass it to the function.
Here are my questions:
Is the ability to remove the
m
fromm t
something 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?