change in overlapping instance behavior between GHC 6.12 and GHC 7 causes compilation failure

1 view
Skip to first unread message

Jeremy Shaw

unread,
Nov 2, 2010, 6:36:45 PM11/2/10
to haskell-cafe
Hello,

I have a module, XMLGenerator, which has some overlapping instances.
I have a second module, Test, which imports that module and also adds
some more overlapping instances.

Both modules contain {-# LANGUAGE OverlappingInstances #-} at the top.

Under some old version of 6.13 (and probably 6.12), if I put both
modules in the same directory and try to load Test.hs, it gets the
error:

Test.hs:16:15:
Overlapping instances for EmbedAsChild (M IO) (XMLGenT m (XML m))
arising from a use of `asChild' at Test.hs:16:15-21
Matching instances:
instance (m1 ~ m, EmbedAsChild m c) =>
EmbedAsChild m (XMLGenT m1 c)
-- Defined at XMLGenerator.hs:16:10-68
instance (XML m ~ x, XMLGen m) => EmbedAsChild m x
-- Defined at XMLGenerator.hs:19:10-51
In the first argument of `($)', namely `asChild'
In the expression: asChild $ (genElement "foo")
In the definition of `asChild':
asChild b = asChild $ (genElement "foo")

If I put the XMLGenerator module in a separate package, dummy-hsx, and
the Test modules links against it, I still get the error.

*but* if I add:

Extensions: OverlappingInstances

to the dummy-hsx.cabal file, then Test.hs compiles just fine! So, for
starters, I do not understand why that happens.

Under GHC 7.0rc1, modifying the .cabal file has no effect. Instead I
always get the error:

Test.hs:16:15:
Overlapping instances for EmbedAsChild (M IO) (XMLGenT m (XML m))
arising from a use of `asChild'
Matching instances:
instance [overlap ok] (m1 ~ m, EmbedAsChild m c) =>
EmbedAsChild m (XMLGenT m1 c)
-- Defined in XMLGenerator
(The choice depends on the instantiation of `m'
To pick the first instance above, use -XIncoherentInstances
when compiling the other instance declarations)

Adding the IncoherentInstances flag does make it compile -- but I have
never enabled that flag and not regretted it.

What changed between GHC 6.12 and GHC 7.0? Is there a some solution
besides using IncoherentInstances in every module that imports
XMLGenerator?

I have attached XMLGenerator.hs, Test.hs, and dummy-hsx.cabal.

thanks!
- jeremy

dummy-hsx.cabal
Test.hs
XMLGenerator.hs

Jeremy Shaw

unread,
Nov 8, 2010, 6:30:38 PM11/8/10
to haskell-cafe, GHC users, Haskell Server Pages
Hello,

I have narrowed this down further to a single file. And created a trac
bug for it:

http://hackage.haskell.org/trac/ghc/ticket/4485

This is (the only thing?) holding up HSP and happstack moving to GHC 7.

- jeremy

Niklas Broberg

unread,
Nov 9, 2010, 6:26:10 AM11/9/10
to haskell-se...@googlegroups.com, haskell-cafe
> What changed between GHC 6.12 and GHC 7.0? Is there a some solution
> besides using IncoherentInstances in every module that imports
> XMLGenerator?

I just want to point out that IncoherentInstances is NOT a solution.
It would probably make the files compile, but not at all with the
semantics we want.

/Niklas

stepcut

unread,
Nov 10, 2010, 1:25:41 PM11/10/10
to Haskell Server Pages
Right. Incoherent is no good.

Seems that both GHC 6.12 and 7.0 are busted. But 6.12 is more busted.
7.0 is mostly working correctly, but the error message does not list
all the relevant instances.

http://hackage.haskell.org/trac/ghc/ticket/4485#comment:2

So, it seems that this is a previously unrecognized design flaw in
HSP :-/

- jeremy
Reply all
Reply to author
Forward
0 new messages