From 01cfd4cfee089323269d7c8324da7c3608edb947 Mon Sep 17 00:00:00 2001 From: simonpj Date: Mon, 4 Apr 2005 13:16:09 +0000 Subject: [PATCH] [project @ 2005-04-04 13:16:09 by simonpj] Documentation for rebindable syntax --- ghc/docs/users_guide/glasgow_exts.xml | 90 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/ghc/docs/users_guide/glasgow_exts.xml b/ghc/docs/users_guide/glasgow_exts.xml index 0b73fbe..377a97c 100644 --- a/ghc/docs/users_guide/glasgow_exts.xml +++ b/ghc/docs/users_guide/glasgow_exts.xml @@ -825,68 +825,68 @@ This name is not supported by GHC. So the flag causes the following pieces of built-in syntax to refer to whatever is in scope, not the Prelude - versions: + versions: - Integer and fractional literals mean - "fromInteger 1" and - "fromRational 3.2", not the - Prelude-qualified versions; both in expressions and in - patterns. - However, the standard Prelude Eq class - is still used for the equality test necessary for literal patterns. - + An integer literal 368 means + "fromInteger (368::Integer)", rather than + "Prelude.fromInteger (368::Integer)". + - - Negation (e.g. "- (f x)") - means "negate (f x)" (not - Prelude.negate). - + Fractional literals are handed in just the same way, + except that the translation is + fromRational (3.68::Rational). + + + The equality test in an overloaded numeric pattern + uses whatever (==) is in scope. + + + The subtraction operation, and the + greater-than-or-equal test, in n+k patterns + use whatever (-) and (>=) are in scope. + - In an n+k pattern, the standard Prelude - Ord class is still used for comparison, - but the necessary subtraction uses whatever - "(-)" is in scope (not - "Prelude.(-)"). - + Negation (e.g. "- (f x)") + means "negate (f x)", both in numeric + patterns, and expressions. + "Do" notation is translated using whatever functions (>>=), - (>>), fail, and - return, are in scope (not the Prelude - versions). List comprehensions, and parallel array + (>>), and fail, + are in scope (not the Prelude + versions). List comprehensions, mdo (), and parallel array comprehensions, are unaffected. - Similarly recursive do notation (see - ) uses whatever - mfix function is in scope, and arrow + Arrow notation (see ) uses whatever arr, (>>>), first, app, (|||) and - loop functions are in scope. - + loop functions are in scope. But unlike the + other constructs, the types of these functions must match the + Prelude types very closely. Details are in flux; if you want + to use this, ask! + - - The functions with these names that GHC finds in scope - must have types matching those of the originals, namely: - - fromInteger :: Integer -> N - fromRational :: Rational -> N - negate :: N -> N - (-) :: N -> N -> N - (>>=) :: forall a b. M a -> (a -> M b) -> M b - (>>) :: forall a b. M a -> M b -> M b - return :: forall a. a -> M a - fail :: forall a. String -> M a - - (Here N may be any type, - and M any type constructor.) - +In all cases (apart from arrow notation), the static semantics should be that of the desugared form, +even if that is a little unexpected. For emample, the +static semantics of the literal 368 +is exactly that of fromInteger (368::Integer); it's fine for +fromInteger to have any of the types: + +fromInteger :: Integer -> Integer +fromInteger :: forall a. Foo a => Integer -> a +fromInteger :: Num a => a -> Integer +fromInteger :: Integer -> Bool -> Bool + + + Be warned: this is an experimental facility, with fewer checks than usual. Use -dcore-lint to typecheck the desugared program. If Core Lint is happy @@ -3488,7 +3488,7 @@ the result type of the case expression. Hence the addition < Notice that GADTs generalise existential types. For example, these two declarations are equivalent: data T a = forall b. MkT b (b->a) - data T' a where { MKT :: b -> (b->a) -> T a } + data T' a where { MKT :: b -> (b->a) -> T' a } -- 1.7.10.4