Type (synonym) families

In 2008, three years after the introduction of associated types, they were subsumed by type families. Associated types are special type families where the type function is attached to a type-class.

In contrast to associated types, we have top-level type-families that are not associated with a type-class, for example:

  type family RepF d
  type instance RepF (List' a) = (RList a)

The type family RepF represents a type function, with each instance declaring a value. Put another way, a type family represents a set of types, and each instance represents a set member.

In our example, GenericF simply uses the top-level type function in its type signatures:

class GenericF d where
  fromF :: d         -> (RepF d)
  toF   :: (RepF d)  -> d

instance ...

Get Haskell Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.