Haskell "evaluates" the reduction to normal or WHNF?

I understand ( I think ) that Haskell seq will (usually) reduce its first WHNF argument, and see how this happens in GHCi:

 λ> let x = (trace "foo" Foo (trace "bar" Bar 100)) in seq x 0 foo 0 

However, although the documentation for evaluate suggests that it also reduces its argument to WHNF, it looks like it actually completely reduces the argument to normal form:

 λ> let x = (trace "foo" Foo (trace "bar" Bar 100)) in evaluate x foo Foo bar (Bar 100) 

I can confirm this (obvious) mismatch with

 λ> let y = (trace "foo" Foo (trace "bar" Bar 100)) λ> seq y 0 foo 0 λ> :sprint y y = <Foo> _ 

and

 λ> let z = (trace "foo" Foo (trace "bar" Bar 100)) λ> evaluate z foo Foo bar (Bar 100) λ> :sprint z z = <Foo> (<Bar> 100) 

If the documentation for evaluate correct, should the behavior of seq and evaluate not match? What am I missing here (as a beginner Haskell)?

+8
haskell lazy-evaluation denotational-semantics
source share
1 answer

What you are missing is that GHCi also prints the result of I / O operations (if they can be shown and are not () ), which leads to its normal operation. Try instead:

 λ> let x = (trace "foo" Foo (trace "bar" Bar 100)) in evaluate x >> return () foo 
+15
source share

All Articles