Changes between Version 9 and Version 10 of FlexibleContexts
- Timestamp:
- 05/08/06 16:30:25 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FlexibleContexts
v9 v10 22 22 [[TicketQuery(description~=FlexibleContexts)]] 23 23 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 {{{ 28 foo :: (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 24 35 == Context reduction == 25 36 Haskell computes a type for each variable bound by `let` or `where`, … … 37 48 is neither allowed nor reducible, so a missing instance `C [a]` is reported. 38 49 39 When contexts are unrestricted, context reduction is forced only by explicit signatures and the type of `main`.50 When 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. 40 51 The above example becomes legal; if a matching instance is in scope when context reduction is forced on uses of `foo`, they will also typecheck: 41 52 {{{ … … 50 61 }}} 51 62 63 The 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 {{{ 66 data Foo = K Bar deriving Eq 67 }}} 68 * ground assertions are fully reduced, so that the following remains illegal: 69 {{{ 70 foo x = x + 'a' 71 }}} 72 52 73 Delaying context reduction: 53 74 * can leave contexts more complex (could interact with the Monomorphism Restriction) … … 55 76 * sometimes avoids nontermination of context reduction for UndecidableInstances 56 77 * 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 Eq61 }}}62 78 63 79 == Pros ==
