Skip to content

Add function equality instance for finite functions to base

If the input type is bounded and enumerable and the result type can be compared for equality, functions can be checked for equality. Basically this instance:

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

I often work with functions with finite domains and find [(a,b)] awkward. I thought this is generic enough that it might belong to base.

I'd also submit a patch, but I couldn't quite figure out where it should live. GHC.Base doesn't have Enum and Bounded; Enum is not where -> or Eq are declared; Eq is not declared anywhere; and Data.Function is only for combinators.

Trac metadata
Trac field Value
Version 8.4.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information