Singular Type Constructor

Hal Daume III
Sun, 12 Aug 2001 19:55:43 -0400 (EDT)

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                                        
"arrest this man, he talks in maths"