Skip to content

Associated data families don't use superclasses when deriving instances

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 constraints

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

-- 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

deriving instance (Key key1, Key key2) => Functor (TotalMap (key1, key2))

Same problem occurs with only a single constraint

-- 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

deriving instance Key key                => Functor (TotalMap (Identity key))
-- or
deriving instance Functor (TotalMap key) => Functor (TotalMap (Identity key))
Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information