Haskell has enough other worthwhile features that it's sometimes easy to
forget one of the most important, laziness, especially if, like me, you
started programming Haskell before SML.

  Not so long back, I finally got around to reading John Hughes famous paper,
"Why Functional Programming Matters".  I don't remember exactly what the
example was, but in that paper there is an eye-opening instance of how
laziness can improve both the design and readability of programs without
incurring a cost in algorithmic efficiency.  The example showed how you can
control the amount of work performed by a function from outside of that
function; thus instead of writing a group of functions which are locally
(i.e., within the function body) optimized for certain properties of their
domain, laziness lets you write one function that is efficient in a variety of
circumstances because the amount of work it performs is demand-regulated.

  And yet, from my experience of using Haskell in a moderately large software
project, it seems easy to lose the advantages of laziness when you are
concentrating on implementing a specification and dealing with the burden of
managing a large number of functions.  In other words, although laziness can
be a sort of "automatic optimization", it still takes some care to ensure that
your programs are not too strict.  There are many examples of this in the
literature (e.g., one that comes to mind is Wadler's "cut" function that
throws out all but the longest match against a Kleene star term in a monadic
parser), and I have found many more while rooting around through GHC's source
code.

  I am interested in hearing from the subscribers of this list, any
interesting concrete examples that people have found where laziness was a
decisive improvement in both the design (i.e., readability and/or
maintainability) and efficiency of a program, or more generally any worthwhile
tips or rules of thumb for increasing laziness.

  There is actually more I would like to discuss in this connection, but I
will wait for some feedback first.

--------------------------------------------------------------------------
Frank Christoph                 Next Solution Co.       Tel: 0424-98-1811
[EMAIL PROTECTED]                              Fax: 0424-98-1500



Reply via email to