Skip to content

Roles for type families

Now that we have roles, it might be helpful to be able to give a role signature for a data/type family.

At the moment, data/type family constructors have all parameters conservatively assigned to be role N. Thus

data family D a    -- Parameter conservatively assumed to be N

class C a where
  op :: D a -> a

instance C Int where ....

newtype N a = MkN a deriving( C )  -- Rejected

The generalised-newtype-deriving clause deriving( C ) is rejected because D might use its parameter at role N thus:

data instance D [b] = MkD (F b)   -- F is a type function

It would be strictly more expressive if we could

  • Declare the roles of D's arguments (as we can declare their kinds). E.g.
data family D a@R
  • Check that each family instance obeys that role signature. E.g. given the preceding role signature, reject this instance:
data instance D [b] = MkD (F b)   -- F is a type function

I think there is no technical difficulty here. Just a question of doing it.

Trac metadata
Trac field Value
Version 7.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC goldfire
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information