#2247: GHC accepts FD violations, unless the conflicing instances are used
-------------------------+--------------------------------------------------
Reporter: claus | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler (Type checker)
Version: 6.9 | Severity: normal
Keywords: TF vs FD | Testcase:
Architecture: Unknown | Os: Unknown
-------------------------+--------------------------------------------------
consider
{{{
class FD a b | a -> b
instance CFD a b => FD a b
class {- FD a b => -} CFD a b
instance CFD Bool Char
instance CFD Bool Bool
f :: CFD Bool Bool => Bool
f = True
g :: CFD Bool Char => Bool
g = False
f' :: FD Bool Bool => Bool
f' = True
g' :: FD Bool Char => Bool
g' = False
}}}
the class instance for `FD` is odd, because there is no guarantee that
instances of `CFD` comply to the FD (and Hugs rejects that instance,
unless the superclass constraint for `CFD` is uncommented). as it stands,
this code specifies two FD-conflicting instances of class `FD`, but they
are implied, not explicit.
GHCi accepts this code, and only complains if the two conflicting
instances are used, explicitly, in the same expression:
{{{
*Main> f
True
*Main> g
False
*Main> (f,g)
(True,False)
*Main> f'
True
*Main> g'
False
*Main> (f',g')
<interactive>:1:0:
Couldn't match expected type `Bool' against inferred type `Char'
When using functional dependencies to combine
FD Bool Char, arising from a use of `g'' at <interactive>:1:4-5
FD Bool Bool, arising from a use of `f'' at <interactive>:1:1-2
When generalising the type(s) for `it'
*Main> do {let {x=f} ;let {y=g} ; return (x,y) }
(True,False)
*Main> do {let {x=f'} ;let {y=g'} ; return (x,y) }
<interactive>:1:0:
Couldn't match expected type `Char' against inferred type `Bool'
When using functional dependencies to combine
FD Bool Bool, arising from a use of `f'' at <interactive>:1:11-12
FD Bool Char, arising from a use of `g'' at <interactive>:1:23-24
When generalising the type(s) for `it'
*Main> let x=f'
*Main> let y=g'
*Main> (x,y)
(True,False)
}}}
so we can have FD-conflicting instances in the same code, even use them in
the same GHCi session, as long as they don't meet in the same line..
for further details and questions, see this message:
[http://www.haskell.org/pipermail/haskell-cafe/2008-April/042219.html some
questions about type improvement, FDs vs TFs, and Hugs vs GHCi]
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2247>
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