Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is `\x -> ⊥ x` equal (under `seq`) to `⊥`, `\x -> ⊥` or nothing at all?

Tags:

haskell

I'm trying to better understand the effect/meaning of seq on ->-typed values, or rather what WHNF means for ->-values.

The Haskell Report defines seq as

seq ⊥ b  =  ⊥
seq a b  =  b,  if a ≠ ⊥

The report also notes that due to those definitions above

⊥ is not the same as \x -> ⊥, since seq can be used to distinguish them

If I have the following definitions

f, g :: () -> ()
g = ⊥
f = \x -> g x

Then f should be syntactically equivalent to g (shouldn't it?), but what should the expressions

seq f ()
seq g ()

according to the Haskell Report evaluate to?

like image 505
hvr Avatar asked Sep 10 '11 13:09

hvr


1 Answers

According to the rules given:

seq f ()
seq (\x -> g x) ()
()

seq g ()
seq ⊥ ()
⊥

This is because (\x -> g x) is a closure, and cannot be evaluated until it's has something to be evaluated on.

An alternative evaluation order:

seq f ()
seq (\x -> g x) ()
seq (\x -> ⊥) ()
()

Still gives the same result.

like image 142
nulvinge Avatar answered Nov 15 '22 07:11

nulvinge