[Haskell-cafe] safe lazy IO or Iteratee?

John Lato jwlato at gmail.com
Thu Feb 4 19:34:06 EST 2010


Hello,

> From: David Leimbach <leimy2k at gmail.com>
>
> Hi everyone,
>
> Yet at the same time, I'm quite enamored with the beauty of "interact" and
> functions of that sort.  I realize mixing the effects of the lazy IO and
> pure code may not be the clearest way to write code for everyone, but there
> is something about being able to get linewise data as
>
> interact (unlines . fmap someLineWiseFunction . lines)
>
> that is just kind of cool.

I think so too.  I really like the "interact" style of code; I find it
supremely elegant.  However I also find it insufficient for many
interesting cases.  One general problem is the difficulty of embedding
monadic code into interact functions.  Usually "interact" requires a
pure function.  Although in many cases I think it would be possible to
have

interactM :: (String -> IO String) -> IO ()

in practice these functions don't usually exist, perhaps because they
can have some surprising behavior.

In my opinion IO is a weakness of Haskell, and many Haskell users
either subconciously or actively seek out alternative approaches.  I
offer as evidence the frequency with which beginners ask the cafe
about "handle closed before data could be read" errors, and also the
proliferation of IO libraries.  I know which I approach I think
represents the best way forward, but I would be surprised if there was
a community consensus at this point.  In any case, I'm glad there are
a multitude of options and each probably has a place and purpose.

Cheers,
John Lato


More information about the Haskell-Cafe mailing list