[Haskell-cafe] Haskell purity and printing
bertram.felgenhauer at googlemail.com
Tue Dec 18 16:31:19 EST 2007
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.
More information about the Haskell-Cafe