On 21-Mar-2000, Sven Panne <[EMAIL PROTECTED]> wrote:
> Example: length is strict in its argument, but the following
> function is hyperstrict (at least according to my definition :-) :
>
> len :: Eq a => [a] -> Int
> len [] = 0
> len (x:xs) | x == x = 1 + len xs
>
> This 'x == x' is folklore for getting rid of some space leaks,
> AFAIK.
Actually, that raises an interesting question:
should instances of `==' be required to be hyperstrict
in cases where they return `True'?
The Haskell report is silent on this issue.
Suppose Sven implements his `len' function as above, and furthermore
implements a library which depends on this function being hyperstrict.
Suppose next that I implement an instance of `==' that returns `True' without
evaluating the arguments, and then finally suppose a third programmer called
say Joe comes along and uses my type with Sven's library. If it breaks, who
is to blame?
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.