<br><br><div class="gmail_quote">2009/4/14 aditya siram <span dir="ltr">&lt;<a href="mailto:aditya.siram@gmail.com">aditya.siram@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
I am trying to understand the TCP Syslog Server example [1] from RWH.<br>
Specifically my question is on this piece of code:<br>
          -- | Process incoming messages<br>
          procMessages :: MVar () -&gt; Socket -&gt; SockAddr -&gt; IO ()<br>
          procMessages lock connsock clientaddr =<br>
              do connhdl &lt;- socketToHandle connsock ReadMode<br>
                 hSetBuffering connhdl LineBuffering<br>
                 messages &lt;- hGetContents connhdl<br>
                 mapM_ (handle lock clientaddr) (lines messages)<br>
                 hClose connhdl<br>
                 handle lock clientaddr<br>
                    &quot;syslogtcpserver.hs: client disconnected&quot;<br>
<br>
How does control stay on &quot;mapM_ (handle lock clientaddr) (lines<br>
messages)&quot; ? It would seem that the server would handle one message<br>
and immediately close the handle and end - but it doesn&#39;t. I&#39;m<br>
guessing this has something to do with laziness, but I don&#39;t see how<br>
to apply it.</blockquote><div><br><br>I think you are right thinking about laziness. The function hGetContents produces a lazy<br>result (messages), therefore  any function that consumes messages could be considered as &#39;iteratively calling&#39; hGetContents to get new elements of messages ...<br>
<br>Laziness is a Very Cool Feature ... when it does not bite you with thunk accumulation problems  :-)<br><br>Ciao<br>------<br>FB<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
thanks ..<br>
-deech<br>
<br>
[1] <a href="http://book.realworldhaskell.org/read/sockets-and-syslog.html" target="_blank">http://book.realworldhaskell.org/read/sockets-and-syslog.html</a><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>
</blockquote></div><br>