<br><br><div class="gmail_quote">2009/4/14 aditya siram <span dir="ltr"><<a href="mailto:aditya.siram@gmail.com">aditya.siram@gmail.com</a>></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 () -> Socket -> SockAddr -> IO ()<br>
procMessages lock connsock clientaddr =<br>
do connhdl <- socketToHandle connsock ReadMode<br>
hSetBuffering connhdl LineBuffering<br>
messages <- hGetContents connhdl<br>
mapM_ (handle lock clientaddr) (lines messages)<br>
hClose connhdl<br>
handle lock clientaddr<br>
"syslogtcpserver.hs: client disconnected"<br>
<br>
How does control stay on "mapM_ (handle lock clientaddr) (lines<br>
messages)" ? It would seem that the server would handle one message<br>
and immediately close the handle and end - but it doesn't. I'm<br>
guessing this has something to do with laziness, but I don'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 'iteratively calling' 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>