[Haskell-cafe] Lazy evaluation and tail-recursion
daniel.is.fischer at googlemail.com
Wed Mar 16 22:50:02 CET 2011
On Wednesday 16 March 2011 22:03:51, Yves Parès wrote:
> Can a type signature give you a hint about whether a function evaluates
> some/all of its arguments (i.e. is strict/partially strict/lazy), or do
> you have to look at the implementation to know?
Cheating, with GHC, a magic hash tells you it's strict (
foo :: Int# -> Double# -> Double
). But generally, a type signature can give at most a hint, because the
implementation could always be
foo _ = undefined -- , Nothing, 0, whatever the result type supports
and hints for laziness tend to be stronger than hints for strictness (
const :: a -> b -> a
hints strongly that it's lazy in the second argument, but it could still be
strict; arguments of type Int, Double or the like have a better than
average chance of being strict).
The only way to know is looking at the implementation, but if the docs say
something about strictness, that should be good enough unless you have
reason to suspect they're wrong.
More information about the Haskell-Cafe