[Haskell-cafe] Comparing functions

David Thomas davidleothomas at gmail.com
Thu Jul 11 20:17:52 CEST 2013

On Thu, Jul 11, 2013 at 10:50 AM, Brandon Allbery <allbery.b at gmail.com>wrote:

> ... but functions don't have an Eq instance, and *can't* have one.

Not a general one that's interesting.

There are two Eq instances that'll compile for all functions (not that it's

instance Eq ((->) a b) where
         (==) _ _ = True

instance Eq ((->) a b) where
         (==) _ _ = False

You can't get more interesting in the general case, because you can't
inspect the arguments.

If you are okay with distinguishing solely by application you can get a
little more interesting:

instance (Bounded a, Enum a, Eq b) => Eq ((->) a b) where
    f == g = all (\ x -> f x == g x) [minBound .. maxBound]

*Main> (&&) == (&&)
*Main> (&&) == (||)

Though I'm still not sure I'd say it's a *good idea*...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130711/23210fd1/attachment.htm>

More information about the Haskell-Cafe mailing list