
On Wed, Feb 24, 2010 at 1:53 PM, Fabian Roth
Hi all, I am trying to read structured data from a socket and return a lazy list of records. However, the socket reading operation seems to be strict and never returns (until stack overflow).
This is expected behaviour. Normal sequencing of IO actions is done in such a way as to preserve their order, which is obviously pretty important if you want to ask for a response to your message after you've sent it, rather than before. Lazy IO operations violate that order and as a result are pretty scary and usually to be avoided. In general, laziness only works well with pure functions where the order doesn't matter because there are no observable side-effects. There are ways of making IO lazy, but there are pretty much invariably other ways of doing the same thing which result in fewer headaches later on. I am hoping that other people more educated than I am will be able to tell you about Iteratees and so forth.