Changes between Version 1 and Version 2 of FlexibleInstances


Ignore:
Timestamp:
Dec 5, 2005 6:18:12 PM (8 years ago)
Author:
ross@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FlexibleInstances

    v1 v2  
    66== Brief Explanation == 
    77 
    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. 
     8In 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. 
    99 
    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 `-fglasgow-exts`. Note that repeated type variables are permitted. 
     10Without restrictions on the form of instances, constraint checking is undecidable (see UndecidableInstances). 
     11A 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. 
    1212 
    13 The non-variable restriction can be onerous if OverlappingInstances are permitted: see UndecidableInstances. 
     13Note that repeated type variables are permitted. 
     14 
     15If the language has FlexibleInstances like 
     16{{{ 
     17instance C [Bool] where ... 
     18instance C [Char] where ... 
     19}}} 
     20assertions like `C [a]` can be neither reduced nor rejected, so FlexibleContexts are also needed. 
    1421 
    1522== References == 
    1623 * [http://www.haskell.org/onlinereport/decls.html#undecidable-instances Instance declarations] in the Haskell 98 Report 
    1724 * [http://research.microsoft.com/Users/simonpj/Papers/type-class-design-space/ 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/type-extensions.html#instance-decls Explanation] in the GHC's User's Guide. 
     25 * [http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#instance-decls Instance declarations] in the GHC's User's Guide. 
    1926 
    2027== Pros ==