[Haskell-cafe] Tutorial on Haskell

Derek Elkins derek.a.elkins at gmail.com
Mon Apr 16 12:41:43 EDT 2007


Mark T.B. Carroll wrote:
> Bryan O'Sullivan <bos at serpentine.com> writes:
> 
>> Mark T.B. Carroll wrote:
>>
>>> I'm afraid no
>>> examples come easily to mind, though.
>> Here's a simple one: reading a flattened graph from disk.  If your 
>> flattened representation contains forward references, you have to fix 
>> them up in a strict language.  In a lazy language, you can refer to 
>> elements you haven't yet read, eliminating that book-keeping.
> 
> That's a good point. Indeed, I had used laziness in a programme that
> read a file that contained a series of entity definitions that could
> include forward references, I just couldn't remember exactly how I'd
> used laziness. (-: (It's also useful in some memoising, I think.)
> 
> -- Mark
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 

Near the bottom of http://www.haskell.org/hawiki/TyingTheKnot is an example that 
uses lazy evaluation to do exactly this.  The real kicker though, is that the 
change from backward references only (i.e. simplistic one-pass code that would 
work in a strict language) to forward and backward references is trivial (just 
pass in the output).


More information about the Haskell-Cafe mailing list