- 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
Hi Oleg,
I'm looking for a type class which checks whether two types are the
same or not.
For the full discussion of various solutions, please see Section 9 and
Appendix D of the HList paper:
http://homepages.cwi.nl/~ralf/HList/paper.pdf
Thanks for pointing that out. As far as I
Thanks for pointing that out. As far as I can see, this requires a new
instance declaration for every type?
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
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
On Wed, Apr 18, 2007 at 01:47:04AM +0100, Neil Mitchell wrote:
- 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