X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=fb21918e2583303d1a611f91dbb982a1b1b71342;hb=2ac0108a79f94b459148a026469aadf594b2fc64;hp=56735d074682be5c75397db0d18875da17e2882a;hpb=1fc88da19dbc66bc12de38b2956e97a8b7835806;p=ghc-hetmet.git diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index 56735d0..fb21918 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -1336,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 @@ -1361,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.) + + + + @@ -1397,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} @@ -1415,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.) + + + @@ -1431,6 +1483,7 @@ same as the field name. Record wildcards are enabled by the flag -XRecordWildCards. +This flag implies -XDisambiguateRecordFields. @@ -1443,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 @@ -1453,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 @@ -1463,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. + + @@ -3087,7 +3157,8 @@ All the extensions are enabled by the flag. Multi-parameter type classes -Multi-parameter type classes are permitted. For example: +Multi-parameter type classes are permitted, with flag . +For example: @@ -3099,13 +3170,17 @@ Multi-parameter type classes are permitted. For example: - + The superclasses of a class declaration -There are no restrictions on the context in a class declaration -(which introduces superclasses), except that the class hierarchy must -be acyclic. So these class declarations are OK: +In Haskell 98 the context of a class declaration (which introduces superclasses) +must be simple; that is, each predicate must consist of a class applied to +type variables. The flag +() +lifts this restriction, +so that the only restriction on the context in a class declaration is +that the class hierarchy must be acyclic. So these class declarations are OK: @@ -4653,7 +4728,11 @@ these type signatures are perfectly OK g :: Eq [a] => ... g :: Ord (T a ()) => ... +The flag also lifts the corresponding +restriction on class declarations () and instance declarations +(). + GHC imposes the following restrictions on the constraints in a type signature. Consider the type: @@ -5986,12 +6065,11 @@ Wiki page. have type Q Exp an type; the spliced expression must have type Q Typ - a list of top-level declarations; the spliced expression must have type Q [Dec] + a list of top-level declarations; the spliced expression + must have type Q [Dec] - Inside a splice you can can only call functions defined in imported modules, - not functions defined elsewhere in the same module. - + not functions defined elsewhere in the same module. A expression quotation is written in Oxford brackets, thus: @@ -6008,7 +6086,7 @@ Wiki page. A quasi-quotation can appear in either a pattern context or an expression context and is also written in Oxford brackets: - [:varid| ... |], + [$varid| ... |], where the "..." is an arbitrary string; a full description of the quasi-quotation facility is given in . @@ -6029,6 +6107,25 @@ Wiki page. + You may omit the $(...) in a top-level declaration splice. + Simply writing an expression (rather than a declaration) implies a splice. For example, you can write + +module Foo where +import Bar + +f x = x + +$(deriveStuff 'f) -- Uses the $(...) notation + +g y = y+1 + +deriveStuff 'g -- Omits the $(...) + +h z = z-1 + + This abbreviation makes top-level declaration slices quieter and less intimidating. + + (Compared to the original paper, there are many differences of detail.