|Version 2 (modified by ross@…, 10 years ago) (diff)|
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.
- 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.
- Instance declarations in the GHC's User's Guide.