I am new to haskell, and have just come to the lazy world proramming. I read that the seq
function is very special because it forces to use a strict evaluation in order to be more efficient in some cases. But I just can't find what seq
stand for literally. Maybe Strict Evaluation Q*???
seq
evaluates its first argument before returning the second one. It is usually introduced to improve performance by avoiding unneeded laziness. It forces evaluation of the function.
seq :: a -> b -> b
seq _ y = y
from prelude.hs
This function definition is wrapped in
#ifdef __HADDOCK__
so it will only be compiled by haddock (the documentation tool), not by the actual compiler! The 'real' seq is defined in GHC.Prim asseq :: a -> b -> b; seq = let x = x in x.
This is only a dummy definition. Basically seq is specially syntax handled particularly by the compiler. You wrote 'seq evaluates its first argument' - but first definition obviously does not do this.
via user2407038
More to read: