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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With