Hi!

Keith Wansbrough wrote:
instance Op_plus MyInt MyInt where
instance (Num a) => Op_plus a MyInt where
instance (Num a) => Op_plus MyInt a where

[..]


Overlapping instance declarations:
  multi.hs:9: Op_plus a MyInt
  multi.hs:12: Op_plus MyInt a
Failed, modules loaded: none.

The GHC manual talks about this at:


http://haskell.cs.yale.edu/ghc/docs/latest/html/users_guide/type-extensions.html#INSTANCE-DECLS

I think the issue is that GHC still requires that overlapping
instances either do not unify, or have an instantiation ordering.
Your 2nd and 3rd instances are unordered: 2 is an instance of 3, and 3
is an instance of 2.  GHC doesn't notice the first instance.

As you mention that documentation, it says:


        GHC is also conservative about committing to an overlapping
        instance. For example:

          class C a where { op :: a -> a }
          instance C [Int] where ...
          instance C a => C [a] where ...

          f :: C b => [b] -> [b]
          f x = op x

        From the RHS of f we get the constraint C [b]. But GHC does not
        commit to the second instance declaration, because in a
        paricular call of f, b might be instantiate to Int, so the first
        instance declaration would be appropriate. So GHC rejects the
        program. If you add -fallow-incoherent-instances GHC will
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        instead silently pick the second instance, without complaining
        about the problem of subsequent instantiations.

I tried -fallow-incoherent-instances but it only worked on that example even the two examples seems to be the same problem. Am I right?

Obs: I'm working with a GHC version 5.04.2. Does it make sens to try the latest 6.0 one?

I observe that the docs above say "Yell if this restriction bites
you.", so I shall hand this over to the GHC developers to discuss
further...

Big 10x! :-) Should I further explain why do I need something like this? And if yes, where should I do this?


--
Razvan ME


_______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

Reply via email to