[Haskell-cafe] Re: instance Eq (a -> b)
Thomas Davie
tom.davie at gmail.com
Wed Apr 14 03:13:15 EDT 2010
Your instances of Finite are not quite right:
bottom :: a
bottom = doSomethingToLoopInfinitely.
instance Finite () where
allValues = [(), bottom]
instance Finite Nothing where
allValues = [bottom]
Though at a guess an allValuesExculdingBottom function is also useful, perhaps the class should be
class Finite a where
allValuesExcludingBottom :: [a]
allValues :: Finite a => [a]
allValues = (bottom:) . allValuesExcludingBottom
Bob
On 14 Apr 2010, at 08:01, Ashley Yakeley wrote:
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list