X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=4e541a696629a2bd23f3275ddb4ada1a2cc0a9f1;hb=d64022dc071b587c20a693b7f355f69dc110b707;hp=c0feb5bff0f803e9588f011dd7a60ae4615b46eb;hpb=aecccd3eae278f4bcc9fc89c9250f889a66d5ded;p=ghc-hetmet.git diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index c0feb5b..4e541a6 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -840,6 +840,19 @@ y) will not be coalesced. + + + +n+k patterns + + + +n+k pattern support is enabled by default. To disable +it, you can use the flag. + + + + @@ -1323,7 +1336,6 @@ module Foo where data T = MkT { x :: Int } ok1 (MkS { x = n }) = n+1 -- Unambiguous - ok2 n = MkT { x = n+1 } -- Unambiguous bad1 k = k { x = 3 } -- Ambiguous @@ -1348,6 +1360,37 @@ if there are other variables in scope with the same name. This reduces the clutter of qualified names when you import two records from different modules that use the same field name. + +Some details: + + +Field disambiguation can be combined with punning (see ). For exampe: + +module Foo where + import M + x=True + ok3 (MkS { x }) = x+1 -- Uses both disambiguation and punning + + + + +With you can use unqualifed +field names even if the correponding selector is only in scope qualified +For example, assuming the same module M as in our earlier example, this is legal: + +module Foo where + import qualified M -- Note qualified + + ok4 (M.MkS { x = n }) = n+1 -- Unambiguous + +Since the constructore MkS is only in scope qualified, you must +name it M.MkS, but the field x does not need +to be qualified even though M.x is in scope but x +is not. (In effect, it is qualified by the constructor.) + + + + @@ -1384,16 +1427,9 @@ a for the same name a. -Note that puns and other patterns can be mixed in the same record: - -data C = C {a :: Int, b :: Int} -f (C {a, b = 4}) = a - -and that puns can be used wherever record patterns occur (e.g. in -let bindings or at the top-level). - - - +Note that: + + Record punning can also be used in an expression, writing, for example, let a = 1 in C {a} @@ -1402,12 +1438,41 @@ instead of let a = 1 in C {a = a} - -Note that this expansion is purely syntactic, so the record pun +The expansion is purely syntactic, so the expanded right-hand side expression refers to the nearest enclosing variable that is spelled the same as the field name. + + + +Puns and other patterns can be mixed in the same record: + +data C = C {a :: Int, b :: Int} +f (C {a, b = 4}) = a + + + + +Puns can be used wherever record patterns occur (e.g. in +let bindings or at the top-level). + + + +A pun on a qualified field name is expanded by stripping off the module qualifier. +For example: + +f (C {M.a}) = a + +means + +f (M.C {M.a = a}) = a + +(This is useful if the field selector a for constructor M.C +is only in scope in qualified form.) + + + @@ -1418,6 +1483,7 @@ same as the field name. Record wildcards are enabled by the flag -XRecordWildCards. +This flag implies -XDisambiguateRecordFields. @@ -1430,7 +1496,7 @@ f (C {a = 1, b = b, c = c, d = d}) = b + c + d -Record wildcard syntax permits a (..) in a record +Record wildcard syntax permits a ".." in a record pattern, where each elided field f is replaced by the pattern f = f. For example, the above pattern can be written as @@ -1440,7 +1506,10 @@ f (C {a = 1, ..}) = b + c + d -Note that wildcards can be mixed with other patterns, including puns +More details: + + +Wildcards can be mixed with other patterns, including puns (); for example, in a pattern C {a = 1, b, ..}). Additionally, record wildcards can be used wherever record patterns occur, including in let @@ -1450,24 +1519,38 @@ C {a = 1, ..} = e defines b, c, and d. - + - + Record wildcards can also be used in expressions, writing, for example, - let {a = 1; b = 2; c = 3; d = 4} in C {..} - in place of - let {a = 1; b = 2; c = 3; d = 4} in C {a=a, b=b, c=c, d=d} - -Note that this expansion is purely syntactic, so the record wildcard +The expansion is purely syntactic, so the record wildcard expression refers to the nearest enclosing variables that are spelled the same as the omitted field names. + + + +The ".." expands to the missing +in-scope record fields, where "in scope" +includes both unqualified and qualified-only. +Any fields that are not in scope are not filled in. For example + +module M where + data R = R { a,b,c :: Int } +module X where + import qualified M( R(a,b) ) + f a b = R { .. } + +The {..} expands to {M.a=a,M.b=b}, +omitting c since it is not in scope at all. + + @@ -7180,24 +7263,11 @@ Assertion failures can be caught, see the documentation for the INCLUDE pragma - The INCLUDE pragma is for specifying the names - of C header files that should be #include'd into - the C source code generated by the compiler for the current module (if - compiling via C). For example: - - -{-# INCLUDE "foo.h" #-} -{-# INCLUDE <stdio.h> #-} - - INCLUDE is a file-header pragma (see ). - - An INCLUDE pragma is the preferred alternative - to the option (), because the - INCLUDE pragma is understood by other - compilers. Yet another alternative is to add the include file to each - foreign import declaration in your code, but we - don't recommend using this approach with GHC. + The INCLUDE used to be necessary for + specifying header files to be included when using the FFI and + compiling via C. It is no longer required for GHC, but is + accepted (and ignored) for compatibility with other + compilers.