[Haskell-cafe] instance Eq (a -> b)

Joe Fredette jfredett at gmail.com
Wed Apr 14 02:24:39 EDT 2010


Consider the set of all rationals with 1 as a numerator, and positive  
denominator, eg:

	S = {1/n, n : Nat}

this is bounded, enumerable, but infinite. Which makes the whole  
checking every value bit somewhat, shall we say, difficult. :)

So for instance, we want to show

	f : S -> S
	f(1/n) = 1/2n

and

	g : S -> S
	g(1/n) = 1/2 * 1/n

would be impossible. Since we would have to check infinitely many  
values of `n`

This, of course, presumes I have understood everything, which seems to  
be less likely every day.


On Apr 14, 2010, at 2:03 AM, Ashley Yakeley wrote:

> 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
>
> _______________________________________________
> 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