[Haskell-cafe] What is <-

Henning Thielemann lemming at henning-thielemann.de
Sun Aug 8 11:36:16 EDT 2010


On Sun, 8 Aug 2010, michael rice wrote:

> That was my suspicion. So, you can't change horses (monads) in mid-stream.
> 
> A parallel question:
> 
> main = do ...    -- in the IO monad
> 
> I know I can have other *do*s in main,
> 
>   if foo
>     then do
>               .
>               .
>     else do
>              .
>              .
> 
> but must all these other *do*s also be in the same IO monad? What determines what monad
> a *do* is "in"? The first line after the *do*?

'do' is just syntactic sugar that is expanded to '>>=' and '>>' 
combinators. Determining the monad is the task of type inference. Since x, 
y and (if b then x else y) must have the same type, so if they are monadic 
actions, they are all of the same monad type.


More information about the Haskell-Cafe mailing list