[Haskell-cafe] Generators? Iterators?
jo at durchholz.org
Sat Apr 23 07:22:51 UTC 2016
Am 23.04.2016 um 07:28 schrieb Christopher Howard:
> I mean, things that
> produce a value as well as function for producing the next value?
In Haskell, the runtime decides when to evaluate things, so the compiler
already compiles every single subexpression into code that can double as
So... you have a list? The code that defines how everything after the
first element should be constructed is already your generator.
You have a tree? The code that defines the content of the child nodes is
already your generator.
You have an arbitrary recursively-defined data structure? The code that
defines things "in the depth" is already a generator.
You don't need to code generators.
Also, you don't need to explicitly call them; you just pull up the
values from the depth of the data structure, and the runtime will decide
when to pull up a cached value or call the generator.
Quite nifty, very flexible (because you never need to rearrange your
code from function to generator or vice versa), somewhat hard to control.
More information about the Haskell-Cafe