Changes between Version 9 and Version 10 of FlexibleContexts


Ignore:
Timestamp:
May 8, 2006 11:30:25 PM (9 years ago)
Author:
ross@…
Comment:

notes on remaining restrictions on contexts

Legend:

Unmodified
Added
Removed
Modified
  • FlexibleContexts

    v9 v10  
    2222[[TicketQuery(description~=FlexibleContexts)]]
    2323
     24== Variations ==
     25 * Hugs requires that type signatures be unambiguous (taking into account FunctionalDependencies).
     26   GHC requires only that type variables in the context be connected (by a chain of assertions) with type variables that occur in the head, so that it accepts
     27   {{{
     28foo :: (C a b, C b c) => c -> Bool
     29}}}
     30   even though such functions cannot be used without ambiguity.
     31
     32 * GHC (but not Hugs) requires that the context contain at least one type variables that is universally quantified at that point.
     33   This is consistent with rejecting inferred types containing irreducible ground assertions (like `Num Char`, see below), which both GHC and Hugs do.
     34
    2435== Context reduction ==
    2536Haskell computes a type for each variable bound by `let` or `where`,
     
    3748is neither allowed nor reducible, so a missing instance `C [a]` is reported.
    3849
    39 When contexts are unrestricted, context reduction is forced only by explicit signatures and the type of `main`.
     50When restrictions on the form of contexts are removed, context reduction is forced only by explicit signatures, the type of `main`, and the few remaining restrictions on contexts.
    4051The above example becomes legal; if a matching instance is in scope when context reduction is forced on uses of `foo`, they will also typecheck:
    4152{{{
     
    5061}}}
    5162
     63The exceptions in GHC and Hugs are:
     64 * contexts of derived instances are fully reduced, so the following instance is allowed only if the instance {{{Eq Bar}}} is in scope:
     65   {{{
     66data Foo = K Bar deriving Eq
     67}}}
     68 * ground assertions are fully reduced, so that the following remains illegal:
     69   {{{
     70foo x = x + 'a'
     71}}}
     72
    5273Delaying context reduction:
    5374 * can leave contexts more complex (could interact with the Monomorphism Restriction)
     
    5576 * sometimes avoids nontermination of context reduction for UndecidableInstances
    5677 * is required by OverlappingInstances
    57 
    58 In GHC and Hugs, the contexts of derived instances are fully reduced, so the following instance is allowed only if the instance {{{Eq Bar}}} is in scope:
    59 {{{
    60 data Foo = K Bar deriving Eq
    61 }}}
    6278
    6379== Pros ==