Exposing newtype coercions to Haskell

Joachim Breitner mail at joachim-breitner.de
Wed Jul 24 09:31:32 CEST 2013


Hi,

Am Dienstag, den 23.07.2013, 18:58 +0000 schrieb Simon Peyton-Jones:
> If you add -XIncoherentInstances *just to the module that has instance
> IsNT a a*, then it'll work fine I think.  This says "pick this
> instance even though an instantiation of the constraint might match a
> more specific instance".  You don't need the flag in importing
> modules.

That does not seem to be the case: Enabling the flag just for the
special "IsNT a a" instance does not work:


Prelude GHC.NT> :t  castNT :: (Either Int a) -> (Either Age a)

<interactive>:1:1:
    Overlapping instances for IsNT a1 a1 arising from a use of ‛castNT’
    Matching instances:
      instance [incoherent] IsNT a a -- Defined at <interactive>:12:10
      instance (IsNT a a', IsNT b b') => IsNT (Either a b) (Either a' b')
        -- Defined at <interactive>:7:1
    (The choice depends on the instantiation of ‛a1’
     To pick the first instance above, use -XIncoherentInstances
     when compiling the other instance declarations)
    In the expression: castNT :: (Either Int a) -> (Either Age a)

(as correctly specified by the error message.)


But now the solution is easy to see: When deriving IsNT, simply set the
incoherent flag for every instance, independent of any active pragmas.

Greetings,
Joachim




-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0x4743206C
  Debian Developer: nomeata at debian.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130724/c899a940/attachment.pgp>


More information about the ghc-devs mailing list