GHC accepts FD violations, unless the conflicing instances are used
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: some questions about type improvement, FDs vs TFs, and Hugs vs GHCi
Trac metadata
Trac field | Value |
---|---|
Version | 6.9 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |