[Haskell-beginners] lazy mapM

Ovidiu D ovidiudeac at gmail.com
Mon Apr 1 01:26:17 CEST 2013


Hi again,

Given the following code:

g :: IO String -> IO String

f :: [IO String] -> IO [ String ]
f = mapM g

The implementation of f is wrong because I would like to:
1. Make f behave lazy
Its input list is made of lines read from stdin and I want it to process
lines one by one as they are entered by the user.

2. Implement  f such that it stops consuming items from the input list when
the input item meets some condition. For example:
isExit item = ("exit" == item)

I tried to implement my own custom iteration by recursion but I got stuck
in the combination of IO and list monads.

Any help is appreciated.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130401/4177aece/attachment.htm>


More information about the Beginners mailing list