[Haskell-cafe] Re: instance Eq (a -> b)
Ashley Yakeley
ashley at semantic.org
Wed Apr 14 03:01:58 EDT 2010
Joe Fredette wrote:
> this is bounded, enumerable, but infinite.
The question is whether there are types like this. If so, we would need
a new class:
class Finite a where
allValues :: [a]
instance (Finite a,Eq b) => Eq (a -> b) where
p == q = fmap p allValues == fmap q allValues
instance (Finite a,Eq a) => Traversable (a -> b) where
sequenceA afb = fmap lookup
(sequenceA (fmap (\a -> fmap (b -> (a,b)) (afb a)) allValues))
where
lookup :: [(a,b)] -> a -> b
lookup (a,b):_ a' | a == a' = b
lookup _:r a' = lookup r a'
lookup [] _ = undefined
instance Finite () where
allValues = [()]
data Nothing
instance Finite Nothing where
allValues = []
--
Ashley Yakeley
More information about the Haskell-Cafe
mailing list