In Haskell we have the function (==) :: Eq a => a->a->Bool
which is fine for the large number of datatypes for which an instance of Eq
can be defined. However there are some types for which there is no reasonable way to define an instance of Eq
. one example is the simple function type (a->b)
I am looking for a function that will tell me if two values are actually the same -- not equal but identical.
For example f(id,id)
==> True
f((+),(-))
= False
Clarification:
I don't want to know if two function do the same thing. It is not possible in the general case to do so. I want to know if I've gotten back the same thing I started with. Let me give a stripped down example:
data Foo = Foo (Foo->Foo) --contains a function so no Eq instance
x :: Foo
x = Foo id -- or for that matter Foo undefined
y :: Foo
y = Foo (const x)
a :: Foo
a = let (Foo fy) = y
in fy x
It is clear that by inspection once evaluated, a
will be x
. But let's assume I don't know the function in y but I want to test if the Foo I put in is the same one I got back - that is does fy x
give me x
. How do I do this?