[Haskell-cafe] Some random newbie questions

Jorge Adriano Aires jadrian at mat.uc.pt
Sun Jan 9 17:57:21 EST 2005

On Sunday 09 January 2005 21:30, Marcin 'Qrczak' Kowalczyk wrote:
> Jorge Adriano Aires <jadrian at mat.uc.pt> writes:
> >> 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?
> Yes. A strict fold would evaluate cons cells of the result while they
> are constructed, not list elements. They are all defined (flip (:) x y
> is always defined), so a strict foldl is correct.

Yes, now I was refering to the efficiency issue only. 

> Making a cons cell should be not more expensive than making a thunk
> which will make a cons cell when evaluated. 

Ok, I wasn't sure about this...

> Well, unless the 
> implementation doesn't inline flip and thus making these thunks
> is actually faster than running them. In this case a lazy foldl is
> more efficient than a strict foldl, as long as a sufficiently small
> part of the result is used; it's always less efficient if the whole
> result is examined.



More information about the Haskell-Cafe mailing list