[Haskell-cafe] Cost of seq (sorry about the old subject)
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Fri Nov 3 09:51:09 EST 2006
"Chad Scherrer" <chad.scherrer at gmail.com> wrote:
> > afaik, seq cost is zero (except for evaluating expressions, of
> > course)
>
> So if x has already been evaluated, does x `seq` y evaluate just as
> quickly as y alone, or does it require extra cycles to make sure x has
> been evaluated?
My understanding is that `seq` does indeed cost extra cycles at runtime
_if it is actually executed_. But of course, the fact that it appears
in your source code does not guarantee that it is executed at runtime.
If the compiler can determine statically (through strictness analysis)
that x is already in evaluated form, then it is at liberty to remove the
`seq` from the code.
Regards,
Malcolm
More information about the Haskell-Cafe
mailing list