
Hi All, One important property of type class dictionary translation is coherence which basically says that two typing derivations for the same term at the same type in the same environment must be equivalent. This definition is established with the assumption of non-overlapping. In the GHC documentation which describes the extension of overlapping instances, an example similar to the following is given.
class C a where f:a -> a instance C Int where f=e1 instance C a where f=e2
let g x = f x in g 1
In this case GHC takes an ¡°incoherent¡± decision by taking the second instance as an instantiation of function f even it is executed with an input of type Int. My question is whether the ¡°incoherence¡± behaviour of overlapping instances is derived from the definition of coherence in the non-overlapping setting? If yes, how is it applicable to rule out the incoherent behaviour? If otherwise, what is the definition of coherence with overlapping instances? Thanks. --william _________________________________________________________________ Find just what you are after with the more precise, more powerful new MSN Search. http://search.msn.com.sg/ Try it now.

| In the GHC documentation which describes the extension of overlapping | instances, an example similar to the following is given. | | >class C a where | > f:a -> a | >instance C Int where | > f=e1 | >instance C a where | > f=e2 | > | >let g x = f x | >in g 1 | | In this case GHC takes an ¡°incoherent¡± decision by taking the second | instance as an instantiation of function f even it is executed with an input | of type Int. No it doesn't (ghc 6.4.1). I've just tried it. It uses the C Int instance, for exactly the reason you describe. There is a flag -fallow-incoherent-instances that _does_ allow incoherence Simon {-# OPTIONS -fallow-overlapping-instances -fglasgow-exts -fallow-undecidable-instances #-} module Main where class C a where f::a -> a instance C Int where f x = x+1 instance C a where f x = x main = print (let g x = f x in g (1::Int))

Thank you Simon. 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? Is there any write-up on this? Thanks. --william
From: "Simon Peyton-Jones"
To: "william kim" , Subject: RE: [Haskell-cafe] coherence when overlapping? Date: Wed, 12 Apr 2006 17:43:33 +0100 | In the GHC documentation which describes the extension of overlapping | instances, an example similar to the following is given. | | >class C a where | > f:a -> a | >instance C Int where | > f=e1 | >instance C a where | > f=e2 | > | >let g x = f x | >in g 1 | | In this case GHC takes an ¡°incoherent¡± decision by taking the second | instance as an instantiation of function f even it is executed with an input | of type Int.
No it doesn't (ghc 6.4.1). I've just tried it. It uses the C Int instance, for exactly the reason you describe.
There is a flag -fallow-incoherent-instances that _does_ allow incoherence
Simon
{-# OPTIONS -fallow-overlapping-instances -fglasgow-exts -fallow-undecidable-instances #-}
module Main where
class C a where f::a -> a instance C Int where f x = x+1 instance C a where f x = x
main = print (let g x = f x in g (1::Int))
_________________________________________________________________ Download MSN Messenger emoticons and display pictures. http://ilovemessenger.msn.com/?mkt=en-sg
participants (2)
-
Simon Peyton-Jones
-
william kim