[Haskell-cafe] seq and lambda with patterns

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Wed Sep 28 12:28:18 UTC 2016


On Wed, Sep 28, 2016 at 03:00:57PM +0300, Denis Moskvin wrote:
> There is some subtle, but reasonable difference between \pat1 pat2 -> expr
> and \pat1 -> \pat2 -> expr:
> 
> > seq ((\True y -> "DEFINED") undefined) 42
> 42
> > seq ((\True -> \y -> "DEFINED") undefined) 42
> *** Exception: Prelude.undefined
> 
> The reason is the translation from Haskell Report 2010 (3.3)
> \ p1 . . . pn -> e = \ x1 . . . xn -> case (x1 , . . . , xn ) of (p1 , . .
> . , pn ) -> e
> 
> 
> Today I found (GHC 8.0.1) that
> 
> > seq ((\True -> \y -> undefined) undefined) 42
> 42
> 
> Is the last result correct?

According to the Haskell report this is

    seq ((\x -> case x of True -> (\y -> undefined)) undefined) 42

and evaluation proceeds to

    case undefined of True -> (\y -> undefined))

and thus to

    undefined

So I agree with you that there's something fishy here.

Tom






More information about the Haskell-Cafe mailing list