Possible Duplicate:
Comparing functions in Haskell
I'm learning haskell, wanted to know is something like this possible? All I want is to compare if parameter 'function' is equal to one of the functions a or b. How to do this?
Example code:
a,b :: Integer -> Integer
a x = x+1
b x = x-1
c function parameter = if function == a
then ... parameter -- Do a related stuff
else ... parameter -- Do b related stuff
The only case I know of where you can compare two functions for equality is if their domain has a finite number of values. For example, if you have two functions of type:
f, g :: Bool -> A
Then they are equal if they are equal for all inputs:
f == g = (f False == g False) && (f True == g True)
However, for the case of Int
, comparing them on every possible value of Int
is impractical and inefficient. For Integer
, it can't be done since Integer
s are unbounded.
As @Miguel correctly pointed out in his comment, functions with non-finite domains cannot be compared for equality in general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With