Changes between Version 1 and Version 2 of FlexibleInstances
 Timestamp:
 Dec 5, 2005 6:18:12 PM (10 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

FlexibleInstances
v1 v2 6 6 == Brief Explanation == 7 7 8 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.8 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. 9 9 10 Allowing arbitrary types in instance heads makes constraint checking undecidable.11 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 `fglasgowexts`. Note that repeated type variables are permitted.10 Without restrictions on the form of instances, constraint checking is undecidable (see UndecidableInstances). 11 A conservative rule that ensures termination (used by GHC with `fglasgowexts`) 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 nonvariable restriction can be onerous if OverlappingInstances are permitted. 12 12 13 The nonvariable restriction can be onerous if OverlappingInstances are permitted: see UndecidableInstances. 13 Note that repeated type variables are permitted. 14 15 If the language has FlexibleInstances like 16 {{{ 17 instance C [Bool] where ... 18 instance C [Char] where ... 19 }}} 20 assertions like `C [a]` can be neither reduced nor rejected, so FlexibleContexts are also needed. 14 21 15 22 == References == 16 23 * [http://www.haskell.org/onlinereport/decls.html#undecidableinstances Instance declarations] in the Haskell 98 Report 17 24 * [http://research.microsoft.com/Users/simonpj/Papers/typeclassdesignspace/ Type classes: exploring the design space] by Simon Peyton Jones, Mark Jones and Erik Meijer, Haskell Workshop 1997. 18 * [http://www.haskell.org/ghc/docs/latest/html/users_guide/typeextensions.html#instancedecls Explanation] in the GHC's User's Guide.25 * [http://www.haskell.org/ghc/docs/latest/html/users_guide/typeextensions.html#instancedecls Instance declarations] in the GHC's User's Guide. 19 26 20 27 == Pros ==