Hi

I guess it depends on how many extensions one may wish to enable. At
the very least we need multi-parameter type classes with functional
dependencies (because that's what TypeEq is in any case).

- If we permit no other extension, we need N^2 instances to compare N
classes for equality (basically, for each type we should say how it
compares to the others). This is not practical except in very limited
circumstances.

- If we permit undecidable instances, one may assign numerals to
types. This gives us total order and hence comparison on types.
In this approach, we only need N instances to cover N types. This is
still better than Typeable because the equality is decided and can be
acted upon at compile time.

In my particular case whether I act at compile time or run time is
unimportant, but obviously this is an important advantage in general.
Unfortunately a cost of one instance per type is still higher than I'd
like to pay :-)

- If we permit overlapping instances extension, then a few lines of code
decide equality for all existing and future types:

        class  TypeEq x y b | x y -> b
        instance TypeEq x x HTrue
        instance TypeCast HFalse b => TypeEq x y b

This is exactly what I was after, but it doesn't seem to work in Hugs
- even with overlapping instances and unsafe overlapping instances
turned on.

*** This instance    : TypeEq a b c
*** Conflicts with   : TypeEq a a HTrue
*** For class        : TypeEq a b c
*** Under dependency : a b -> c

Is there any way to modify this to allow it to work under Hugs as well?

Thanks very much for your help,

Neil
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to