[Haskell-beginners] Getting a specified number of lines from stdin
frantisek kocun
frantisek.kocun at gmail.com
Fri Mar 11 15:34:23 UTC 2016
Here is the answer
http://stackoverflow.com/questions/34910992/iterate-io-actions-and-laziness
You need to write recursive function, not to use iterage or to
liftM (take 5) $ sequence $ repeat (unsafeInterleaveIO getLine)
On Sun, Mar 6, 2016 at 11:38 AM, Nicolaas du Preez <njdupreez at yahoo.com>
wrote:
> Good day All,
>
> Why does
>
> liftM (take 5) $ sequence $ repeat getLine
>
> not stop at reading only 5 lines from stdin but keeps on reading more?
>
> What I’m really trying to achieve is to get input from the user until
> an empty line is read with the code below. But this doesn’t work
> as I expected, similar to the above.
>
> liftM (takeWhile (/= "")) $ sequence $ repeat getLine
>
>
> Regards,
> Nicolaas du Preez
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160311/9de4b881/attachment.html>
More information about the Beginners
mailing list