#2356: GHC accepts multiple instances for the same type in different modules
----------------------+-----------------------------------------------------
Reporter: claus | Owner:
Type: bug | Status: new
Priority: low | Milestone: _|_
Component: Compiler | Version: 6.8.3
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
----------------------+-----------------------------------------------------
Comment (by claus):
Replying to [comment:8 igloo]:
> Here is an example of Data.Set going wrong due to multiple instances:
That depends on what you define as wrong, doesn't it?-)
In the Haskell'98 view, there is at most one instance for a class/type, so
if you give such an instance, you may conclude that it is the only one, so
the behaviour is wrong.
In the Ghc view, local instances are supported unless they actually
conflict in use, so you may not conclude that the instance you see is the
only one there'll ever be, so the behaviour is not wrong per se, just one
of many possible behaviours.
In particular, you explicitly force Ghc to commit to the local instances
leaving it no room for using other instances or reporting conflicts. If
the functions where `memberBy` and `fromListBy`, with explicit comparison
parameters, you're supplying the comparisons at the point of definition
for `f` and `s`, instead of allowing them to be supplied at the point of
use (where a conflict between differing comparisons might be noted).
If, instead you ask Ghc to leave the instances to use open, the behaviour
will be closer to what you expected:
{{{
s :: Set Foo
f :: Set Foo -> Bool
}}}
would become (needs `{-# LANGUAGE FlexibleContexts #-}`)
{{{
s :: Ord Foo => Set Foo
f :: Ord Foo => Set Foo -> Bool
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2356#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs