[Haskell] line-based interactive program

Colin Runciman colin at cs.york.ac.uk
Fri Jul 8 09:51:11 EDT 2005


>>buffer xs = foldl const xs xs
>>I don't find it this easy nor a good programming practise.
I don't see why you should think it hard to define a function like
'buffer'.  The whole purpose of foldl is to encapsulate accumulation. 
It demands the full spine of its list argument to produce any result,
and that's what we want.  And we don't want any extra computation, just
the list argument itself; hence 'const' and 'xs'.

Your implicitly proposed "programming practise" is actually *not to
program* buffering at all!   Just have it as an ad hoc IO directive,
programmed less concisely and no more clearly in a low-level library or
run-time system.  How is that better?

>>My interaction depends on the (subtle order of) evaluation of a pure and
>>total function?
Pure, yes; total, no.

Many important things depend on order of evaluation in lazy programs:
for example, whether they compute a well-defined value at all!   The
interleaving of demand in the argument of a function with computational
progress in its result seems a perfectly natural view of interaction in
a lazy functional language.  This sort of interaction is what actually
happens when your function applications are evaluated whether you
exploit it or not.  I embrace it as part of lazy functional programming;
you prefer an appeal to something extraneous.

[I am conscious that we are using bandwidth on the main Haskell mailing
list for this little discussion -- perhaps we are about done, but if not
perhaps we should mail each other direct.]

Colin R

More information about the Haskell mailing list