[Haskell-cafe] Laziness question
michael rice
nowgate at yahoo.com
Sat Jul 31 11:56:04 EDT 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100731/e2676304/attachment.html
More information about the Haskell-Cafe
mailing list