summaryrefslogtreecommitdiff
path: root/compiler/deSugar/MatchCon.lhs
diff options
context:
space:
mode:
authorLemmih <lemmih@gmail.com>2007-06-21 09:15:52 +0000
committerLemmih <lemmih@gmail.com>2007-06-21 09:15:52 +0000
commit2eb04ca0f8d0ec72b417cddc60672c696b4a3daa (patch)
tree2e6450922401768e3774f792479292fdba625f66 /compiler/deSugar/MatchCon.lhs
parent74b27e20425336403d80e942ee3faf00f8c36ef8 (diff)
downloadhaskell-2eb04ca0f8d0ec72b417cddc60672c696b4a3daa.tar.gz
Add several new record features
1. Record disambiguation (-fdisambiguate-record-fields) In record construction and pattern matching (although not in record updates) it is clear which field name is intended even if there are several in scope. This extension uses the constructor to disambiguate. Thus C { x=3 } uses the 'x' field from constructor C (assuming there is one) even if there are many x's in scope. 2. Record punning (-frecord-puns) In a record construction or pattern match or update you can omit the "=" part, thus C { x, y } This is just syntactic sugar for C { x=x, y=y } 3. Dot-dot notation for records (-frecord-dot-dot) In record construction or pattern match (but not update) you can use ".." to mean "all the remaining fields". So C { x=v, .. } means to fill in the remaining fields to give C { x=v, y=y } (assuming C has fields x and y). This might reasonably considered very dodgy stuff. For pattern-matching it brings into scope a bunch of things that are not explictly mentioned; and in record construction it just picks whatver 'y' is in scope for the 'y' field. Still, Lennart Augustsson really wants it, and it's a feature that is extremely easy to explain. Implementation ~~~~~~~~~~~~~~ I thought of using the "parent" field in the GlobalRdrEnv, but that's really used for import/export and just isn't right for this. For example, for import/export a field is a subordinate of the *type constructor* whereas here we need to know what fields belong to a particular *data* constructor. The main thing is that we need to map a data constructor to its fields, and we need to do so in the renamer. For imported modules it's easy: just look in the imported TypeEnv. For the module being compiled, we make a new field tcg_field_env in the TcGblEnv. The important functions are RnEnv.lookupRecordBndr RnEnv.lookupConstructorFields There is still a significant infelicity in the way the renamer works on patterns, which I'll tackle next. I also did quite a bit of refactoring in the representation of record fields (mainly in HsPat).***END OF DESCRIPTION*** Place the long patch description above the ***END OF DESCRIPTION*** marker. The first line of this file will be the patch name. This patch contains the following changes: M ./compiler/deSugar/Check.lhs -3 +5 M ./compiler/deSugar/Coverage.lhs -6 +7 M ./compiler/deSugar/DsExpr.lhs -6 +13 M ./compiler/deSugar/DsMeta.hs -8 +8 M ./compiler/deSugar/DsUtils.lhs -1 +1 M ./compiler/deSugar/MatchCon.lhs -2 +2 M ./compiler/hsSyn/Convert.lhs -3 +3 M ./compiler/hsSyn/HsDecls.lhs -9 +25 M ./compiler/hsSyn/HsExpr.lhs -13 +3 M ./compiler/hsSyn/HsPat.lhs -25 +63 M ./compiler/hsSyn/HsUtils.lhs -3 +3 M ./compiler/main/DynFlags.hs +6 M ./compiler/parser/Parser.y.pp -13 +17 M ./compiler/parser/RdrHsSyn.lhs -16 +18 M ./compiler/rename/RnBinds.lhs -2 +2 M ./compiler/rename/RnEnv.lhs -22 +82 M ./compiler/rename/RnExpr.lhs -34 +12 M ./compiler/rename/RnHsSyn.lhs -3 +2 M ./compiler/rename/RnSource.lhs -50 +78 M ./compiler/rename/RnTypes.lhs -50 +84 M ./compiler/typecheck/TcExpr.lhs -18 +18 M ./compiler/typecheck/TcHsSyn.lhs -20 +21 M ./compiler/typecheck/TcPat.lhs -8 +6 M ./compiler/typecheck/TcRnMonad.lhs -6 +15 M ./compiler/typecheck/TcRnTypes.lhs -2 +11 M ./compiler/typecheck/TcTyClsDecls.lhs -3 +4 M ./docs/users_guide/flags.xml +7 M ./docs/users_guide/glasgow_exts.xml +42
Diffstat (limited to 'compiler/deSugar/MatchCon.lhs')
-rw-r--r--compiler/deSugar/MatchCon.lhs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/deSugar/MatchCon.lhs b/compiler/deSugar/MatchCon.lhs
index 3f25fc7a6e..ed9f2c1204 100644
--- a/compiler/deSugar/MatchCon.lhs
+++ b/compiler/deSugar/MatchCon.lhs
@@ -119,11 +119,11 @@ conArgPats :: DataCon
-> [Type] -- Instantiated argument types
-- Used only to fill in the types of WildPats, which
-- are probably never looked at anyway
- -> HsConDetails Id (LPat Id)
+ -> HsConDetails (LPat Id) (HsRecFields Id (LPat Id))
-> [Pat Id]
conArgPats data_con arg_tys (PrefixCon ps) = map unLoc ps
conArgPats data_con arg_tys (InfixCon p1 p2) = [unLoc p1, unLoc p2]
-conArgPats data_con arg_tys (RecCon rpats)
+conArgPats data_con arg_tys (RecCon (HsRecFields rpats _))
| null rpats
= -- Special case for C {}, which can be used for
-- a constructor that isn't declared to have