Version 2 (modified by ross@…, 12 years ago) (diff)

Flexible Instances

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

Brief Explanation

In Haskell 98, instance declarations must have the form instance (C1 v1, …, Cn vn) => C (T u1 … uk), where T is a type constructor defined by a data or newtype declaration (see TypeSynonymInstances) and the ui are distinct type variables.

Without restrictions on the form of instances, constraint checking is undecidable (see UndecidableInstances). A conservative rule that ensures termination (used by GHC with -fglasgow-exts) is to require instance heads of the form instance (C1 vs1, …, Cn vsn) => C t1 … tk, where at least one of the ti is not a type variable (assuming MultiParamTypeClasses). The non-variable restriction can be onerous if OverlappingInstances are permitted.

Note that repeated type variables are permitted.

If the language has FlexibleInstances like

instance C [Bool] where ...
instance C [Char] where ...

assertions like C [a] can be neither reduced nor rejected, so FlexibleContexts are also needed.



  • Pro
  • Pro


  • Con
  • Con