[Haskell-cafe] Lazy lists vs generators

oleg at okmij.org oleg at okmij.org
Sat Jun 11 11:06:36 CEST 2011

Yves Pare`s  wrote:

> I cannot help smiling when I hear Java/C#/Python developers telling about
> the "wondeful features" of their languages ;)
> (- We have generators! We can _yield_ values! [1]
>  - Yeah, so nice... We have simple lists... with lazy evaluation)

Just for the record, lazy lists per se are sufficient only for
simplest generators. Re-writing an accumulating traversal to
accommodate suspension by hand is too ungainly and error prone. Still,
if we just add exceptions (the Either monad), we can idiomatically
write all the generator examples of Python or Icon, for example. If we
do not need effects other than yielding or non-determinism, [Either e a],
which is ErrorT e [] a, suffices. If we need IO or mutable state,
we should replace [] with LogicT (which is the monad of lazy lists
with effect).

The following web page talks about lazy lists and generators 
in (perhaps too) great detail.

More information about the Haskell-Cafe mailing list