#1614: Type checker does not use fundep to avoid ambiguity
----------------------------------------+-----------------------------------
    Reporter:  guest                    |        Owner:         
        Type:  bug                      |       Status:  new    
    Priority:  normal                   |    Milestone:  6.8    
   Component:  Compiler (Type checker)  |      Version:  6.7    
    Severity:  normal                   |   Resolution:         
    Keywords:                           |   Difficulty:  Unknown
          Os:  MacOS X                  |     Testcase:         
Architecture:  x86                      |  
----------------------------------------+-----------------------------------
Comment (by guest):

 What I'm really trying to use this for is to solve a different problem,
 which might have a more direct solution.  I have an instance 'Eq (E RValue
 a)' and I want the type checker to pick that one when it runs into the
 constraint 'Eq (E v a)', because there's never going to be any other
 instance of 'Eq (E ...)'.
 Of course, the type checker needs to be convinced of this.  So I tried
 'IsRValue v => Eq (E v a)', where IsRValue has a fundep that forces it to
 have (at most) one instance.
 But then I ran into the bug I reported.

 I think using this idiom is a reasonable way to tell the type checker that
 there will be at most one instance of a particular class.

 The code:
 {{{
 {-# OPTIONS_GHC -fglasgow-exts #-}
 module E where

 data E v a = E a
 data RValue

 {-
 -- This fails with the message below.
 instance (Eq a) => Eq (E RValue a) where
     E x == E y  =  x == y
 --    No instance for (Eq (E v Int))
 --      arising from a use of `==' at E.hs:13:6-11
 -}

 -- This succeeds, but doesn't force v to be RValue
 instance (Eq a) => Eq (E v a) where
     E x == E y  =  x == y

 {-
 -- This fails with the message below.
 instance (IsRValue v, Eq a) => Eq (E v a) where
     E x == E y  =  x == y
 class IsRValue a | -> a
 instance IsRValue RValue
 --    Ambiguous type variable `v' in the constraint:
 --      `IsRValue v' arising from a use of `==' at E.hs:30:6-11
 -}

 a :: E v Int
 a = undefined

 foo = a == a
 }}}

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