[Haskell-cafe] Laziness question
michael rice
nowgate at yahoo.com
Sat Jul 31 12:59:39 EDT 2010
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 ().
But since both still have eval x to *thunk* : *thunk*, g evaluates "to a deeper level?"
Michael
> Wouldn't both functions need to evaluate x to the same level, *thunk* : *thunk* to insure listhood?
>
> f x = length [head *thunk* : *thunk*]
> g x = length (tail *thunk* : *thunk*)
>
> Michael
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
Notice the two different kinds of brackets being used in f versus g :)
--- On Sat, 7/31/10, Ben Millwood <haskell at benmachine.co.uk> wrote:
From: Ben Millwood <haskell at benmachine.co.uk>
Subject: Re: [Haskell-cafe] Laziness question
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
Date: Saturday, July 31, 2010, 12:38 PM
On Sat, Jul 31, 2010 at 4:56 PM, michael rice <nowgate at yahoo.com> wrote:
>
> From: http://en.wikibooks.org/wiki/Haskell/Laziness
>
>
> Given two functions of one parameter, f and g, we say f is stricter than g if f x evaluates x to a deeper level than g x
>
> Exercises
>
> 1. Which is the stricter function?
>
> f x = length [head x]
> g x = length (tail x)
>
>
>
> Prelude> let f x = length [head x]
> Prelude> let g x = length (tail x)
> Prelude> f undefined
> 1
> Prelude> g undefined
> *** Exception: Prelude.undefined
> Prelude>
>
>
>
> So, g is stricter than f?
>
> Wouldn't both functions need to evaluate x to the same level, *thunk* : *thunk* to insure listhood?
>
> f x = length [head *thunk* : *thunk*]
> g x = length (tail *thunk* : *thunk*)
>
> Michael
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
Notice the two different kinds of brackets being used in f versus g :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100731/8b570bce/attachment-0001.html
More information about the Haskell-Cafe
mailing list