
18 Dec
2007
18 Dec
'07
4:31 p.m.
Cristian Baboi wrote:
This is what I "understand" so far ...
Suppose we have these two values: a) \x->x + x b) \x->2 * x Because these to values are equal, all functions definable in Haskell must preserve this.
Oh but you can distinguish these functions. Consider
a x = x+x b x = 2*x
data T = A | B deriving (Show, Eq)
instance Num T where _ + _ = A _ * _ = B
f :: (T -> T) -> T f y = y undefined
main = print (f a) >> print (f b)
which prints A, then B. The key point here is that a and b have type (Num a => a -> a) and while well behaved Num instances certainly can not distinguish a and b, artificial ones like above can. Enjoy, Bertram