#816: Weird fundep behavior (with -fallow-undecidable-instances)
----------------------------------------+-----------------------------------
    Reporter:  nibro                    |        Owner:         
        Type:  bug                      |       Status:  new    
    Priority:  normal                   |    Milestone:         
   Component:  Compiler (Type checker)  |      Version:  6.4.2  
    Severity:  normal                   |     Keywords:         
          Os:  Unknown                  |   Difficulty:  Unknown
Architecture:  Unknown                  |  
----------------------------------------+-----------------------------------
I encounter a strange behavior with functional dependencies. Assume we
 have a class defined as

 class Foo x y | x -> y where
  foo :: x -> y

 and another class

 class Bar x y where
  bar :: x -> y -> Int

 and I want to write the instance declaration

 instance (Foo x y, Bar y z) => Bar x z where
  bar x z = bar (foo x) z

 Compiling (with 6.4.2, -fallow-undecidable-instances and -fglasgow-exts) I
 get the following error message:
 <error>
 Foo.hs:12:0:
     Context reduction stack overflow; size = 21
     Use -fcontext-stack20 to increase stack size to (e.g.) 20
         `$dBar :: Bar y z' arising from use of `bar' at Foo.hs:13:11-13
         [... same thing 20 times ...]
         `$dBar :: Bar y z' arising from use of `bar' at Foo.hs:13:11-13
         `bar :: {bar at [y z]}' arising from use of `bar' at Foo.hs:13:11-
 13
     When trying to generalise the type inferred for `bar'
       Signature type:     forall x y z. (Foo x y, Bar y z) => x -> z ->
 Int
       Type to generalise: x -> z -> Int
     In the instance declaration for `Bar x z'
 </error>

 The declaration requires undecidable instances, but I doubt that the
 problem comes from that. What makes it even more weird is that I can get
 this to compile, and behave as expected, if I do one of a) declare an
 instance of Bar for any type, or
 b) add an explicit type signature (foo x :: y) in the definition of Bar.
 The first seems weird since how could a different, unrelated instance
 affect the typeability of the second instance? The second, b), is weird
 since by the FD x -> y we should already know that foo x :: y.

 Same behavior in GHC 6.4.1. Hugs (with -98 +O) accepts the code.

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