[Haskell-beginners] A question about an infinite type
Costello, Roger L.
costello at mitre.org
Tue Feb 28 13:52:19 CET 2012
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?
More information about the Beginners