[Haskell-cafe] Maintaining laziness: another example
jac at informatik.uni-kiel.de
Mon Jun 8 08:57:55 EDT 2009
this is a very nice example.
On 08.06.2009, at 14:31, Eugene Kirpichov wrote:
> Cool! Probably one should start teaching with 'case' instead of
> pattern function definitions; that would put an accent on what is
> forced and in what order.
I like this idea.
> Only after the student understands the laziness issues, introduce
> pattern signatures.
But I think this will not solve the problem. Even for an experienced
Haskell programmer it is not easy to check whether a function is too
strict. I think it would be helpful if you define your functions using
case expressions but in general you do not want to do this. For
example consider the implementation of insect of Data.List.
intersect xs ys = [x | x <- xs, any (==x) ys]
This definition is too strict. The evaluation of intersect  [1..]
yields  while the evaluation of intersect [1..]  does not
terminate. This function can be improved such that it yields the empty
list in both cases. This function was probably not implemented by a
Haskell novice ; )
More information about the Haskell-Cafe