[Haskell-cafe] unsafeInterleaveST (and IO) is really unsafe [was: meaning of "referential transparency"]

oleg at okmij.org oleg at okmij.org
Fri Apr 12 10:44:42 CEST 2013


> Lazy I/O *sounds* safe.
> And most of the alternatives (like conduits) hurt my head,
> so it is really *really* tempting to stay with lazy I/O and
> think I'm doing something safe.

Well, conduit was created for the sake of a web framework. I think all
web frameworks, in whatever language, are quite complex, with a steep
learning curve. As to alternatives -- this is may be the issue of
familiarity or the availability of a nice library of combinators.

Here is the example from my FLOPS talk: count the number of words
"the" in a file.

Lazy IO:

run_countTHEL fname = 
 readFile fname >>= print . length . filter (=="the") . words

Iteratee IO:

run_countTHEI fname = 
  print =<< fileL fname >$< wordsL >$< filterL (=="the") >$< count_i

The same structure of computation and the same size (and the same
incrementality). But there is even a simple way (when it applies):
generators. All languages that tried generators so far (starying from
CLU and Icon) have used them to great success.

> Derek Lowe has a list of "Things I Won't Work With".
> http://pipeline.corante.com/archives/things_i_wont_work_with/
This is a really fun site indeed.





More information about the Haskell-Cafe mailing list