#1624: internal error caused by adding an instance to a type class with a
functional dependency and a default method
--------------------------------------+-------------------------------------
  Reporter:  int-e                    |          Owner:       
      Type:  bug                      |         Status:  new  
  Priority:  normal                   |      Milestone:       
 Component:  Compiler (Type checker)  |        Version:  6.7  
  Severity:  normal                   |       Keywords:       
Difficulty:  Unknown                  |             Os:  Linux
  Testcase:                           |   Architecture:  x86  
--------------------------------------+-------------------------------------
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.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1624>
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

Reply via email to