overlapping instances and constraints
bulat.ziganshin at gmail.com
Tue Feb 28 05:29:34 EST 2006
Tuesday, February 28, 2006, 4:23:24 AM, you wrote:
>> i had plans to propose the same and even more:
>> instance C2 a b | a/=b
JM> I was thinking it would be all kinds of useful if we had two predefined
JM> class Eq a b
JM> class NEq a b
JM> where Eq has instances exactly when its two types are equal and NEq has
JM> instances exactly when its two types are not equal.
JM> Eq should be straightforward to implement, declaring any type
JM> automatically creates its instances. (sort of an auto-deriving). NEq
JM> might be more problematic as that would involve a quadratic number of
JM> instances so its implementation might need to be more special. but
JM> perhaps we can do with just 'Eq'.
with 'Eq' class we can't do anything that is impossible without it
the whole devil is to make general instance NON-OVERLAPPING with
specific one by EXPLICITLY specifying EXCLUSIONS with these "/=" rules:
class Convert a b where
cvt :: a->b
instance Convert a a where -- are we need Eq here? :)
cvt = id
instance (NEq a b) => Convert a b where
cvt = read.show
... yes, i recalled! my proposal was to allow "!" in instance headers:
instance C Int where ...
instance (!Int a, Integral a) => C a where ...
instance (!Integral a, Enum a) => C a where ...
adding your Eq class, it will be all we can do on this way
interesting, that the language theoretics can say about decidability,
soundness, and so on of this trick? :)
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-prime