I'm confused about the description of how Haskell's seq
works in a tutorial I'm reading.
The tutorial states that
evaluating the expression
seq x y
will first evaluatex
to WHNF and only then continue with the evaluation ofy
But earlier the same tutorial, in explaining how Haskell's lazy evaluation works in general, states that in evaluating a function, argues are "evaluated, but only as far as necessary" which means that its
arguments will be evaluated from left to right until their topmost nodes are constructors that match the pattern. If the pattern is a simple variable, then the argument is not evaluated; if the pattern is a constructor, this means evaluation to WHNF.
This description of function evaluation in general, seems no different from the description given for seq
. Both — in my beginner's reading — just reduce their first argument to WHNF.
Is that correct? How is seq
different — specifically in how it processes its first argument — from any other Haskell function?