
At 2001-08-08 23:00, Hal Daume III wrote:
however, if you try something like:
instance TypeName a where typeName T = "??"
it will complain because there must be one non-type variable in the instance head.
Try using "-fglasgow-exts -fallow-undecidable-instances".
moreover, even if this restriction is removed (anyone know what it's there for?), there will be the problem of overlapping instances with, say TypeName Char and TypeName a.
Correct. And the instances really would overlap, it wouldn't just be GHC complaining that they _might_ overlap but not being able to figure out that they don't.
so i'm wondering if there is a way to specify something like:
instance Not (TypeName a) => TypeName a where ...
No.
that is, this type variable a matches with all a such that a is not an instance of TypeName...
If there were such a thing, it would be incoherent to say: "if a is not TypeName, then a is TypeName with this typeName".
there are other places where i would find such a thing useful/interesting beyond this TypeName foo, but this seemed like a good, simple way to explain it...
Can you think of a use for it that isn't semantically incoherent? -- Ashley Yakeley, Seattle WA

On Thu, 9 Aug 2001, Ashley Yakeley wrote:
At 2001-08-08 23:00, Hal Daume III wrote: If there were such a thing, it would be incoherent to say: "if a is not TypeName, then a is TypeName with this typeName".
there are other places where i would find such a thing useful/interesting beyond this TypeName foo, but this seemed like a good, simple way to explain it...
Can you think of a use for it that isn't semantically incoherent?
So say you wanted to define a sort of "equality" on pairs (this isn't made up -- I wanted to do just this, recently). Say you have: data MyPair a b = MyPair a b instance (Eq a, Eq b) => Eq (MyPair a b) where (MyPair a b) == (MyPair a' b') = (a == a') && (b == b') this is obvious. but supposing you wanted a sort of relaxed equality wherein, if you chould check for equality on the second element, you would, otherwise you would just check the first element. i would want to say something like: instance (Eq a, Not (Eq b)) => Eq (MyPair a b) where (MyPair a _) == (MyPair a' _) = a == a' But from what you're telling me there's no way to have both of these instances, correct? - Hal ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hal Daume III hal@cmu.edu "arrest this man, he talks in maths" www.andrew.cmu.edu/~hcd ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So say you wanted to define a sort of "equality" on pairs (this isn't made up -- I wanted to do just this, recently). Say you have:
data MyPair a b = MyPair a b
instance (Eq a, Eq b) => Eq (MyPair a b) where (MyPair a b) == (MyPair a' b') = (a == a') && (b == b')
this is obvious. but supposing you wanted a sort of relaxed equality wherein, if you chould check for equality on the second element, you would, otherwise you would just check the first element. i would want to say something like:
instance (Eq a, Not (Eq b)) => Eq (MyPair a b) where (MyPair a _) == (MyPair a' _) = a == a'
But from what you're telling me there's no way to have both of these instances, correct?
How about using overlapping instances? Add: instance Eq a where _ == _ = True to your program: if there isn't a ``better'' instance, it'll use this one. Such an instance declaration is inherently dangerous to have around, but might help your particular situation. Some tests: Main> MyPair 1 2 == MyPair 1 3 False Main> MyPair 1 (\x -> x+1) == MyPair 1 (\x -> x+12) True Don't forget to start hugs with flags: +o -98 (I haven't tried with ghc.) Admittedly, this is quite horrible and should be avoided if possible. -Levent.
participants (3)
-
Ashley Yakeley
-
Hal Daume III
-
Levent Erkok