[Haskell-cafe] What is <-

michael rice nowgate at yahoo.com
Sun Aug 8 11:27:01 EDT 2010


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*?

Thanks for your patience.

Michael

--- On Sun, 8/8/10, Henning Thielemann <lemming at henning-thielemann.de> wrote:

From: Henning Thielemann <lemming at henning-thielemann.de>
Subject: Re: [Haskell-cafe] What is <-
To: "michael rice" <nowgate at yahoo.com>
Date: Sunday, August 8, 2010, 11:01 AM


On Sun, 8 Aug 2010, michael rice wrote:

> How would I print each of these integers, one per line?
> 
> [1,2,3,4,5] >>= \x -> ?

You can't do this from inside the List monad, but you can easily do it from outside, since the result of a 'do' block in List monad is just a list.

  mapM_ print [1..5]

or

  mapM_ print $ do
     x <- [1..]
     ...
     return (x+y+z)



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100808/c8f55bee/attachment-0001.html


More information about the Haskell-Cafe mailing list