First-class types
Simon Peyton-Jones
simonpj@microsoft.com
Wed, 5 Mar 2003 09:12:37 -0000
| 1) Coerce a a can be defined as coerce=3Did for all a. However, this
| may of course lead to overlap in the type structure, so we must
| write a separate instance definition for Coerce Int Int, Coerce
| Double Double, etc. if we want types to be decidable. I'd love for
| some clever person to solve this little difficulty.
Indeed so. And=20
instance Coerce a a where coerce =3D id
does not overlap with
instance Coerce Int Bool where ...
instance Coerce Bool Int where ...
There's no overlap here. (Overlap =3D there is a Coerce t1 t2, which
matches more than one instance decl.) Furthermore, it works fine; I
just tried it.
| 2) When we define D a b c, we know that D b a c is also allowed.
| Again, decidability prevents us from asserting this directly.
| Again, a clever solution could save us a lot of code and even more
| debugging. I suspect this may be a marginally easier nut to crack
| than the previous one.
Much harder, I think. Commutativity is always tricky!
Simon