A question about an infinite type

Hi Folks, Here is an interesting phenomena: let f = (\x y -> x y x) let p = (\x y -> 1) Now let's evaluate f p 1 f p 1 = (\x y -> x y x) p 1 -- by replacing f with its definition = p 1 p -- by substituting x with p and y with 1 = (\x y -> 1) 1 p -- by replacing the first p with its definition = 1 -- the function returns 1 regardless of its arguments However, Haskell will not proceed with that evaluation because it will first determine the type signature of f and judge it to be an infinite type. Conversely, if f is omitted and this expression p 1 p is evaluated then the result 1 is generated. Why does f p 1 (which evaluates to p 1 p) fail whereas p 1 p succeeds? What lesson should I learn from this example? /Roger

You can find your answer here:
http://en.wikibooks.org/wiki/Haskell/YAHT/Type_advanced
On Tue, Feb 28, 2012 at 12:52 PM, Costello, Roger L.
Hi Folks,
Here is an interesting phenomena:
let f = (\x y -> x y x)
let p = (\x y -> 1)
Now let's evaluate f p 1
f p 1 = (\x y -> x y x) p 1 -- by replacing f with its definition
= p 1 p -- by substituting x with p and y with 1
= (\x y -> 1) 1 p -- by replacing the first p with its definition
= 1 -- the function returns 1 regardless of its arguments
However, Haskell will not proceed with that evaluation because it will first determine the
type signature of f and judge it to be an infinite type.
Conversely, if f is omitted and this expression
p 1 p
is evaluated then the result 1 is generated.
Why does f p 1 (which evaluates to p 1 p) fail whereas p 1 p succeeds?
What lesson should I learn from this example?
/Roger
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (2)
-
Costello, Roger L.
-
Lorenzo Bolla