internal error caused by adding an instance to a type class with a functional dependency and a default method
I've got trouble with the following program:
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
class Foo a b | a -> b where
foo :: a -> b
foo = undefined
instance Foo a (Maybe a)
This results in a type checking error, and an internal error:
xx.hs:2:0:
Couldn't match expected type `b' (a rigid variable)
against inferred type `Maybe a'
`b' is bound by the class declaration for `Foo'
When using functional dependencies to combine
Foo a (Maybe a), arising from the instance declaration at x.hs:8:0
Foo a b,
arising from is bound by the class declaration for `Foo'
at x.hs:(2,0)-(4,18)
[snip]
x.hs:6:0:
GHC internal error: `Main.$dmfoo' is not in scope
In the expression: Main.$dmfoo
In the definition of `foo': foo = Main.$dmfoo
In the definition for method `foo'
Slightly less convincing variations on the scheme are
class Foo a b | a -> b
instance Foo a (Maybe a)
foo :: Foo a b => a -> b
foo = undefined
class Bar a b c
instance (Foo a b, Foo b c) => Bar a b c
Both the definition of foo
and the instance declaration of Bar
give a type checking error "when combining functional dependencies".
Apparently ghc
doesn't use functional dependencies to simplify the contexts of user supplied type signatures; I think the above examples indicate that it should.
Trac metadata
Trac field | Value |
---|---|
Version | 6.7 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |