Changes between Version 1 and Version 2 of FlexibleContexts


Ignore:
Timestamp:
Dec 12, 2005 2:57:54 PM (8 years ago)
Author:
ross@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FlexibleContexts

    v1 v2  
    1515(Similar relaxation of `instance` declarations leads to UndecidableInstances.) 
    1616 
     17== Context reduction == 
     18Haskell computes a type for each variable bound by `let` or `where`, 
     19and then generalizes this type. 
     20In Haskell 98, the allowed contexts are restricted, so contexts are reduced using `instance` declarations (and duplicate assertions and those implied by `class` contexts are removed) until either they are in the allowed form or no instance is applicable, in which case an error is reported. For example, in the following 
     21{{{ 
     22module M where 
     23class C a where c_method :: a -> Bool 
     24foo xs = c_method (tail xs) 
     25}}} 
     26the context of the inferred type 
     27{{{ 
     28foo :: C [a] => [a] -> Bool 
     29}}} 
     30is neither allowed nor reducible, so a missing instance `C [a]` is reported. 
     31 
     32When contexts are unrestricted, context reduction is forced only by explicit signatures and the type of `main`. 
     33The above example becomes legal; if a matching instance is in scope when context reduction is forced on uses of `foo`, they will also typecheck: 
     34{{{ 
     35import M 
     36instance C [a] where c_method = null 
     37 
     38main :: IO () 
     39main = print (foo "abc") 
     40}}} 
     41 
     42Delaying context reduction: 
     43 * can leave contexts more complex (could interact with the Monomorphism Restriction) 
     44 * delays (and sometimes avoids) type errors 
     45 * sometimes avoids nontermination of context reduction 
     46 * is required by OverlappingInstances 
     47 
    1748== References == 
    1849 * [http://www.haskell.org/onlinereport/decls.html#sect4.1.3 Syntax of Class Assertions and Contexts] in the Haskell 98 Report