Wed Apr 12 22:18:02 EDT 2006

```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" <simonpj at microsoft.com>
>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))
>

_________________________________________________________________