[Haskell-cafe] instance Eq (a -> b)
Ashley Yakeley
ashley at semantic.org
Wed Apr 14 02:03:59 EDT 2010
Why isn't there an instance Eq (a -> b) ?
allValues :: (Bounded a,Enum a) => [a]
allValues = enumFrom minBound
instance (Bounded a,Enum a,Eq b) => Eq (a -> b) where
p == q = fmap p allValues == fmap q allValues
Of course, it's not perfect, since empty types are finite but not
Bounded. One can nevertheless make them instances of Bounded with
undefined bounds, and have enumFrom and friends always return the empty
list.
It seems one should also be able to write
instance (Bounded a,Enum a) => Traversable (a -> b) where ???
But this turns out to be curiously hard.
--
Ashley Yakeley
More information about the Haskell-Cafe
mailing list