wiki:TypeSynonymInstances

Version 4 (modified by ross@…, 8 years ago) (diff)

--

Type Synonym Instances

Ticket(s)

See ExtensionDescriptionHowto for information on how to write these extension descriptions. Please add any new extensions to the list of HaskellExtensions.

Brief Explanation

Haskell 98 permits only type constructors defined using data or newtype in instance heads.

The proposal is to allow type synonyms (fully applied, as ever) in instance heads. These would be fully expanded before any other restrictions on instance heads were checked (see FlexibleInstances and OverlappingInstances).

Not very useful without either FlexibleInstances or UndecidableInstances.

References

Pros

  • Offered by GHC and Hugs for several years.
  • Synonyms can cut large instance heads to a manageable size, e.g. when building a monad using monad transformers.
  • Allows a library author to generalize types while retaining source compatibility with old client instances. e.g. replacing
    data T a = ...
    
    with
    data GenT param a = ...
    type T = GenT Default
    

Cons

  • Since constraints on the instance head refer to the expanded type, errors can be more obscure.