#2102: Typeclass membership doesn't bring coercion superclass requirements into
scope
-------------------------+--------------------------------------------------
    Reporter:  ryani     |        Owner:         
        Type:  bug       |       Status:  new    
    Priority:  normal    |    Milestone:         
   Component:  Compiler  |      Version:  6.8.2  
    Severity:  normal    |   Resolution:         
    Keywords:            |     Testcase:         
Architecture:  Unknown   |           Os:  Unknown
-------------------------+--------------------------------------------------
Comment (by ryani):

 This is related to a feature request:
 http://hackage.haskell.org/trac/ghc/ticket/2101

 Here's the motivating example:
 {{{
 type family Cat ts0 ts
 type instance Cat ()      ts' = ts'
 type instance Cat (s, ts) ts' = (s, Cat ts ts')

 class (Cat ts () ~ ts) => Valid ts
 instance Valid () -- compiles OK
 instance Valid ts => Valid (s, ts) -- fails to compile

 -- need to prove Cat (s, ts) () ~ (s, Cat ts ())
 -- for the superclass of class Valid.
 -- (1) From Valid ts: Cat ts () ~ ts
 -- (2) Therefore:     (s, Cat ts ()) ~ (s, ts)

 coerce :: forall f ts. Valid ts => f (Cat ts ()) -> f ts
 coerce x = x
 }}}

 GHC gives the following two errors:
 {{{
 tyfam.hs:38:0:
     Couldn't match expected type `ts' against inferred type `Cat ts ()'
       `ts' is a rigid type variable bound by
            the instance declaration at tyfam.hs:38:15
     When checking the super-classes of an instance declaration
     In the instance declaration for `Valid (s, ts)'

 tyfam.hs:46:11:
     Couldn't match expected type `ts' against inferred type `Cat ts ()'
       `ts' is a rigid type variable bound by
            the type signature for `coerce' at tyfam.hs:45:19
       Expected type: f ts
       Inferred type: f (Cat ts ())
     In the expression: x
     In the definition of `coerce': coerce x = x
 }}}

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