[Haskell-cafe] Re: [Haskell] A puzzle and an annoying feature

Keean Schupke k.schupke at imperial.ac.uk
Fri Nov 26 04:43:00 EST 2004

Seeing as we are taling about type class extensions, can you see any 
with the following...

class X x
instance Int
instance Float
instance x

Here we have overlapping instances... (bad), but if we look at the cases 
is one which will match 'x' but never any of the others... that is when the
overloading is unresolved... like in:

    show (read y)

suppose we replace X with

class X x y | x -> y
instance Int Int
instance Float Float
instance x Int

What we mean is for 'x' to catch anything that does not match (not Int 
or Float)...
but this is broken because the programs meaning can change when extra 
are added... But considering above, the 'unresolved condition' is 
included in x, as
well as all the overlapping cases... so is it safe to say:

class X x y | x -> y
instance Int Int
instance Float Float
instance (_|_) Int

Where (_|_) is some symbol that represents "no match is possible" or a 
failure of
the overloading resolution... This _cannot_ overlap with the other 
instances, and
is distinct (the meaning does not change if instances are added)...

This could be used to force resolution in unresolvable cases (much like 
default to Integer is ambiguous)...

Any thoughts?


More information about the Haskell-Cafe mailing list