I was reading the purescript wiki and found following section which explains do in terms of >>=.
What does >>= mean?
Do notation
The do keyword introduces simple syntactic sugar for monadic expressions.
Here is an example, using the monad for the
Maybetype:maybeSum :: Maybe Number -> Maybe Number -> Maybe Number maybeSum a b = do n <- a m <- b let result = n + m return result
maybeSumtakes two values of typeMaybe Numberand returns their sum if neither number isNothing.When using do notation, there must be a corresponding instance of the Monad type class for the return type. Statements can have the following form:
a <- xwhich desugars tox >>= \a -> ...xwhich desugars tox >>= \_ -> ...or just x if this is the last statement.- A let binding
let a = x. Note the lack of theinkeyword.The example
maybeSum desugars to::maybeSum a b = a >>= \n -> b >>= \m -> let result = n + m in return result