RE: [Haskell-cafe] Re: coherence when overlapping?

2006-04-16 Thread Martin Sulzmann
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

[Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread william kim
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

[Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread Martin Sulzmann
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

Re: [Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread Martin Sulzmann
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

RE: [Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread Simon Peyton-Jones
| 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

RE: [Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread william kim
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

[Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread oleg
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

Re: [Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread Claus Reinke
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

[Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread Aaron Denney
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

[Haskell-cafe] Re: coherence when overlapping?

2006-04-12 Thread oleg
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)