[Haskell-cafe] Some random newbie questions
Jorge Adriano Aires
jadrian at mat.uc.pt
Sun Jan 9 16:20:16 EST 2005
> No, it would work with strict foldl too. In fact in the absence
> of optimization it would work better (uses less time and space).
> The optimization required is inlining and strictness analysis.
Is this also true if your just going to use the first few elements after
reversing it?
> A function which requires lazy foldl for correctness would have
> to be sometimes lazy in its first argument, and at the same time
> some partial results would have to be undefined. By "function"
> I mean the first argument of foldl, treated as a binary function.
>
> Here this doesn't apply because flip (:) x y is always defined. And
> another common case for foldl, sum, doesn't apply because (+) is
> usually strict on both arguments (although in principle it does not
> have to be true because of overloading, which implies that a compiler
> can only optimize particular specializations of sum, not generic sum).
>
> I don't know of any real-life example.
Yes you are right, my bad. I was thinking as if lists were not lazy on their
elements, therefore my second example... But yes, now it is not a common
example anymore.
> Perhaps there are cases where evaluating partial results is correct
> but inefficient. I don't know such case either.
Just replace the errors on my second example by some big computations...
J.A.
More information about the Haskell-Cafe
mailing list