[Haskell-cafe] lazy evaluation is not complete

Jochem Berndsen jochem at functor.nl
Mon Feb 9 10:19:29 EST 2009


Peter Padawitz wrote:
> A simplied version of Example 5-16 in Manna's classical book
> "Mathematical Theory of Computation":
>
> foo x = if x == 0 then 0 else foo (x-1)*foo (x+1)
>
> If run with ghci, foo 5 does not terminate, i.e., Haskell does not look
> for all outermost redices in parallel. Why? For efficiency reasons?
>
> It's a pity because a parallel-outermost strategy would be complete.

(*) is strict in both arguments for Int. If you want to avoid this, you
could do
newtype X = X Int
and write your own implementation of (*) that is nonstrict.

-- 
Jochem Berndsen | jochem at functor.nl
GPG: 0xE6FABFAB


More information about the Haskell-Cafe mailing list