[Haskell-cafe] Laziness question
Ben Millwood
haskell at benmachine.co.uk
Sat Jul 31 13:47:18 EDT 2010
On Sat, Jul 31, 2010 at 5:59 PM, michael rice <nowgate at yahoo.com> wrote:
>
> OK, in f, *length* already knows it's argument is a list.
>
> In g, *length* doesn't know what's inside the parens, extra evaluation there. So g is already ahead before we get to what's inside the [] and ().
According to the types, we already know both are lists. The question
is, of course, what kind of list.
> But since both still have eval x to *thunk* : *thunk*, g evaluates "to a deeper level?"
>
> Michael
>
I think this question is being quite sneaky. The use of head and tail
is pretty much irrelevant. Try the pointfree versions:
f = length . (:[]) . head
g = length . tail
and see if that helps you see why f is lazier than g.
More information about the Haskell-Cafe
mailing list