#4028: Derived Data instance requires Data instances for unused type parameters
----------------------------------------+-----------------------------------
    Reporter:  igloo                    |        Owner:              
        Type:  bug                      |       Status:  new         
    Priority:  normal                   |    Milestone:  Not GHC     
   Component:  Compiler (Type checker)  |      Version:  6.12.2      
    Keywords:                           |   Difficulty:              
          Os:  Unknown/Multiple         |     Testcase:              
Architecture:  Unknown/Multiple         |      Failure:  None/Unknown
----------------------------------------+-----------------------------------
Changes (by simonpj):

 * cc: leat...@…, dreixel (added)
  * milestone:  6.14.1 => Not GHC


Comment:

 I've had a chance to look at this.  Sadly, 6.10 is wrong here; the change
 was the fix to #3087.  The derived instance looks like this, as you'll see
 if you do -ddump-deriv:
 {{{
 instance (Data s, Data a) => Data (FSVec s a) where
     dataCast2 f           = Data.Typeable.gcast2 f    -- <-------  NOTA
 BENE
     dataTypeOf _          = tFSVec
     toConstr (FSVec _)    = cFSVec
     gunfold k z _         = k (z FSVec)
     gfoldl k z (FSVec a1) = (z FSVec `k` a1)
 cFSVec = Data.Data.mkConstr tFSVec "FSVec" ["unFSVec"] Data.Data.Prefix
 tFSVec = Data.Data.mkDataType "T4028.FSVec" [cFSVec]
 }}}
 The new bit, compared to 6.10, is the definition of `dataCast2`.  It is
 defined in the Data class thus
 {{{
 class Data a where
   dataCast2 :: Typeable2 t
             => (forall d e. (Data d, Data e) => c (t d e))
             -> Maybe (c a)
 }}}
 and `gcast2` has this type:
 {{{
 gcast2 :: forall t,t',a,b.  (Typeable2 t, Typeable2 t')
        => c (t a b) -> Maybe (c (t' a b))
 }}}
 Now to typecheck the instance
 {{{
 instance (Data a, Data s) => Data (FSVec s a) where
    dataCast2 f = gcast2 f
 }}}
 we need that `(Data a, Data s)` context.  Try that exact instance
 declaration and you'll see. And there you are.

 If you want to know about `dataCast2` it's all in Section 7 of the SYB2
 paper http://research.microsoft.com/en-
 us/um/people/simonpj/papers/hmap/gmap2.ps.

 If you don't need `dataCast2` you can define it to return `Nothing`:
 {{{
   dataCast2 f = Nothing
 }}}
 but you can't use `deriving` for that; you'd have to write out the derived
 instance yourself.

 I'm not sure how to help you here.  I can see that since 's' is phantom it
 seems odd to require `(Data s)` but that's what the type checker will
 require.  My brain has forgotten the details of `dataCast2` and friends.

 Maybe some generic programming experts (at Utrecht, for example) might
 help? I'm adding Sean Leather to the cc list.

 I'll leave this open, but not because there is a bug as specified; rather
 maybe there is a better design of the Data library waiting to be
 discovered.  I'll milestone it as 'Not GHC' though.

 I suppose another design would be for derived 'Data' not to define
 `dataCast1,2`, but #3087 specifically asked for them to be so!

 Simon

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