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

2010-04-14 Thread Ashley Yakeley
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.

Re: [Haskell-cafe] instance Eq (a - b)

2010-04-14 Thread Ivan Miljenovic
On 14 April 2010 16:03, Ashley Yakeley ash...@semantic.org wrote: Why isn't there an instance Eq (a - b) ? How do you prove that f = (2*) and g x = x + x are equal? Mathematically, you can; but the only way you can prove it in Haskell is by comparing the values for the entire domain (which gets

Re: [Haskell-cafe] instance Eq (a - b)

2010-04-14 Thread Joe Fredette
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

Re: [Haskell-cafe] instance Eq (a - b)

2010-04-14 Thread Ashley Yakeley
On Wed, 2010-04-14 at 16:11 +1000, Ivan Miljenovic wrote: but the only way you can prove it in Haskell is by comparing the values for the entire domain (which gets computationally expensive)... It's not expensive if the domain is, for instance, Bool. -- Ashley Yakeley

Re: [Haskell-cafe] instance Eq (a - b)

2010-04-14 Thread Jonas Almström Duregård
I guess nontermination is a problem (e.g. if one or both functions fail to terminate for some values, equality will be undecidable). /Jonas On 14 April 2010 08:42, Ashley Yakeley ash...@semantic.org wrote: On Wed, 2010-04-14 at 16:11 +1000, Ivan Miljenovic wrote: but the only way you can prove

Re: [Haskell-cafe] instance Eq (a - b)

2010-04-14 Thread Ketil Malde
Joe Fredette jfred...@gmail.com writes: 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. Isn't making this an instance of Enum something of an abuse? How would you use enumFromThenTo

Re: [Haskell-cafe] instance Eq (a - b)

2010-04-14 Thread Ivan Lazar Miljenovic
Ashley Yakeley ash...@semantic.org writes: On Wed, 2010-04-14 at 16:11 +1000, Ivan Miljenovic wrote: but the only way you can prove it in Haskell is by comparing the values for the entire domain (which gets computationally expensive)... It's not expensive if the domain is, for instance,