<div dir="ltr"><div><div><div>I know you have the best intentions in writing this, but there are pitfalls.  Unexpected things happen when you interleave IO in this manner, but nonetheless, here&#39;s how you would do it.<br>
<br>myGetLine = do<br>  x &lt;- getLine<br>  if (x == &quot;exit&quot;)<br>      then return []<br>      else do<br>        xs &lt;- unsafeInterleaveIO myGetLine<br>        return (x:xs)<br><br>main = do<br>  x &lt;- myGetLine<br>
</div><div>  print x<br><br></div><div>Just know that at some point you should learn to use conduits or pipes for a much better approach to modeling things like this.<br></div><div><br></div></div></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sun, Mar 31, 2013 at 7:26 PM, Ovidiu D <span dir="ltr">&lt;<a href="mailto:ovidiudeac@gmail.com" target="_blank">ovidiudeac@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div><div>Hi again,<br><br>Given the following code:<br><br>g :: IO String -&gt; IO String<br><br>f :: [IO String] -&gt; IO [ String ]<br>f = mapM g<br></div><div><br>The implementation of f is wrong because I would like to:<br>

</div><div>1. Make f behave lazy<br></div><div>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.<br><br></div><div>2. Implement  f such that it stops consuming items from the input list when the input item meets some condition. For example:<br>

isExit item = (&quot;exit&quot; == item)<br></div><div><br>I tried to implement my own custom iteration by recursion but I got stuck in the combination of IO and list monads.<br><br></div><div>Any help is appreciated.<br>

<br></div><div>Thanks!<br></div><div><br></div></div></div></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>