
#12863: Associated data families don't use superclasses when deriving instances -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs class Functor (TotalMap key) => Key key where data TotalMap key :: Type -> Type (¡) :: TotalMap key val -> key -> val }}} a constraint `Key key` entails a `Functor (TotalMap key)` constraint, using the notation of [https://hackage.haskell.org/package/constraints constraints] {{{#!hs prf1 :: Key key :- Functor (TotalMap key) prf1 = Sub Dict prf2 :: (Key key1, Key key2) :- (Functor (TotalMap key1), Functor (TotalMap key2)) prf2 = prf1 *** prf1 }}} Yet these proofs are not used in {{{#!hs -- tzLp.hs:28:89-95: error: … -- • No instance for (Functor (TotalMap key1)) -- arising from the first field of ‘PairMap’ -- (type ‘TotalMap key1 (TotalMap key2 val)’) -- Possible fix: -- use a standalone 'deriving instance' declaration, -- so you can specify the instance context yourself -- • When deriving the instance for (Functor (TotalMap (key1, key2))) -- Compilation failed. instance (Key key1, Key key2) => Key (key1, key2) where data TotalMap (key1, key2) val = PairMap (TotalMap key1 (TotalMap key2 val)) deriving Functor (¡) :: TotalMap (key1, key2) val -> ((key1, key2) -> val) PairMap keys ¡ (k1, k2) = keys ¡ k1 ¡ k2 }}} I would expect it to work like {{{#!hs deriving instance (Key key1, Key key2) => Functor (TotalMap (key1, key2)) }}} Same problem occurs with only a single constraint {{{#!hs -- tzLp.hs:33:14-20: error: … -- • No instance for (Functor (TotalMap key)) -- arising from the first field of ‘Id’ (type ‘TotalMap key val’) -- Possible fix: -- use a standalone 'deriving instance' declaration, -- so you can specify the instance context yourself -- • When deriving the instance for (Functor -- (TotalMap (Identity key))) -- Compilation failed. instance Key key => Key (Identity key) where data TotalMap (Identity key) val = Id (TotalMap key val) deriving Functor }}} which should work like {{{#!hs deriving instance Key key => Functor (TotalMap (Identity key)) -- or deriving instance Functor (TotalMap key) => Functor (TotalMap (Identity key)) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12863 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler