Version 1 (modified by ross@…, 8 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 heads 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.

Allowing arbitrary types in instance heads makes constraint checking undecidable.
One rule that ensures termination 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). This is the rule used by GHC with `-fglasgow-exts`. Note that repeated type variables are permitted.

The non-variable restriction can be onerous if OverlappingInstances are permitted: see UndecidableInstances.

## References

- Instance declarations in the Haskell 98 Report
- Type classes: exploring the design space by Simon Peyton Jones, Mark Jones and Erik Meijer, Haskell Workshop 1997.
- Explanation in the GHC's User's Guide.

## Pros

- Pro
- Pro

## Cons

- Con
- Con