Haskell puzzles!

Rijk J. C. van Haaften rjchaaft@cs.uu.nl
Thu, 21 Mar 2002 14:38:05 +0100


Zdenek Dvorak wrote:
>>-----------------------------------------------------
>>1) Are e1 and e2 equal?
>>
>> > f (x:xs) y  = x
>> > g (x:xs)    = \y -> x
>> >
>> > e1 = seq (f []) 1
>> > e2 = seq (g []) 1
>
>Should not these be
>
>f (x:xs) y  = y
>g (x:xs)    = \y -> y
>?
>Otherwise, both e1 and e2 are obviously undefined.
That seems to be obvious, but e1 is NOT undefined!
That's the point Daan makes.

seq forces it's first argument and returns the second one.
However, because f is partially parametrized, seq doesn't
change anything in f and just returns 1. The right-hand-side
of f is not involved at all!
In e2 though, g is fully parametrized, so seq behaves as
you expect and the pattern match failes.

Rijk-Jan