[Haskell-cafe] Laziness enhances composability: an example
Simon Richard Clarkstone
simon.clarkstone at gmail.com
Fri Jul 10 21:21:09 EDT 2009
Thomas Davie wrote:
> On 9 Jul 2009, at 14:55, Cristiano Paris wrote:
>> I'm wondering what a good example of why laziness enhances
>> composability would be.
>>
>> I'm specifically looking for something that can't implemented in
>> Python with iterators (at least not elegantly), but can actually be
>> implemented in Haskell.
>
> Pretty much anything that uses "tying the knot" is very difficult to
> implement in a non-lazy language without a lot of indirection.
I disagree; mutation can work rather well instead.
One application I work on has to parse input containing items with
forward and backward references using keys into a graph of objects, a
classic tying-the-knot problem. However, we are not using a lazy
language, so have only one procedure to create or look up the object
corresponding to an item, by key. Parsing references to an item will
just store the returned address, but parsing the definition of an item
will mutate the object to fill in the data. The effect is that all the
references end up as pointers to the right objects, and the objects for
undefined items end up keeping their default values (caught by later
checks).
Situations like that make either mutation or laziness very handy, and if
one cannot imagine the "tying the knot" technique then mutation looks
like the only good way. No wonder people don't "get" pure FP! ;-)
--
src/
More information about the Haskell-Cafe
mailing list