Coherence may also arise because of an ambiguous type.
Here's the classic example.
class Read a where read :: String - a
class Show a where show :: a - String
f s = show (read s)
f has type String-String, therefore we can pick
some arbitrary Read/Show classes.
If you want to know
Thank you oleg.
Sulzmann et al use guards in CHR to turn overlapping heads (instances) into
non-overlapping. Their coherence theorem still assumes non-overlapping.
I agree that what you described is the desirable behaviour when overlapping,
that is to defer the decision when multiple
Coherence (roughly) means that the program's semantics is independent
of the program's typing.
In case of your example below, I could type the program
either use the first or the second instance (assuming
g has type Int-Int). That's clearly bound.
Guard constraints enforce that instances are
I believe that GHC's overlapping instance extensions
effectively uses inequalities.
Why do you think that 'inequalities' model 'best-fit'?
instance C Int -- (1)
instance C a-- (2)
under a 'best-fit' instance reduction strategy
we would resolve C a by using (2).
'best-fit' should
| I believe that GHC's overlapping instance extensions
| effectively uses inequalities.
I tried to write down GHC's rules in the manual:
http://haskell.org/ghc/dist/current/docs/users_guide/type-extensions.htm
l#instance-decls
The short summary is:
- find candidate instances that match
- if
Thank you Martin.
Coherence (roughly) means that the program's semantics is independent
of the program's typing.
In case of your example below, I could type the program
either use the first or the second instance (assuming
g has type Int-Int). That's clearly bound.
If g has type Int-Int, it
It seems that the subject is a bit more complex, and one can force GHC
to choose the less specific instance (if one confuses GHC well
enough): see the example below.
First of all, the inequality constraint is already achievable in
Haskell now: TypeEq t1 t2 False is such a constraint. One can
one can force GHC to choose the less specific instance (if one
confuses GHC well enough): see the example below.
your second example doesn't really do that, though it may look that way.
class D a b | a - b where g :: a - b
instance D Int Bool where g x = True
instance TypeCast Int b = D a b
On 2006-04-13, Martin Sulzmann [EMAIL PROTECTED] wrote:
I believe that GHC's overlapping instance extensions
effectively uses inequalities.
Why do you think that 'inequalities' model 'best-fit'?
instance C Int -- (1)
instance C a-- (2)
under a 'best-fit' instance reduction
But I am still confused by the exact definition of coherence in the case of
overlapping. Does the standard coherence theorem apply? If yes, how?
If no, is there a theorem?
Yes, the is, by Martin Sulzmann et al, the Theory of overloading (the
journal version)
10 matches
Mail list logo