simonpj 2003/06/24 00:58:28 PDT
Modified files:
ghc/compiler/deSugar DsExpr.lhs DsListComp.lhs DsMonad.lhs
DsUtils.lhs
ghc/compiler/hsSyn Convert.lhs HsExpr.lhs HsSyn.lhs
ghc/compiler/main CmdLineOpts.lhs DriverFlags.hs
HscMain.lhs ParsePkgConf.y
ghc/compiler/parser Lex.lhs Parser.y RdrHsSyn.lhs
ghc/compiler/prelude PrelNames.lhs
ghc/compiler/rename RnEnv.lhs RnExpr.lhs RnHiFiles.lhs
RnHsSyn.lhs
ghc/compiler/typecheck Inst.lhs TcEnv.lhs TcExpr.lhs
TcHsSyn.lhs TcMType.lhs TcMatches.lhs
TcMonoType.lhs TcPat.lhs TcRnDriver.lhs
TcRnMonad.lhs TcRnTypes.lhs TcUnify.lhs
Added files:
ghc/compiler/deSugar DsArrows.lhs
ghc/compiler/typecheck TcArrows.lhs
Log:
----------------------------------------------
Add support for Ross Paterson's arrow notation
----------------------------------------------
Ross Paterson's ICFP'01 paper described syntax to support John Hughes's
"arrows", rather as do-notation supports monads. Except that do-notation is
relatively modest -- you can write monads by hand without much trouble --
whereas arrow-notation is more-or-less essential for writing arrow programs.
It desugars to a massive pile of tuple construction and selection!
For some time, Ross has had a pre-processor for arrow notation, but the
resulting type error messages (reported in terms of the desugared code)
are impenetrable. This commit integrates the syntax into GHC. The
type error messages almost certainly still require tuning, but they should
be better than with the pre-processor.
Main syntactic changes (enabled with -farrows)
exp ::= ... | proc pat -> cmd
cmd ::= exp1 -< exp2 | exp1 >- exp2
| exp1 -<< exp2 | exp1 >>- exp2
| \ pat1 .. patn -> cmd
| let decls in cmd
| if exp then cmd1 else cmd2
| do { cstmt1 .. cstmtn ; cmd }
| (| exp |) cmd1 .. cmdn
| cmd1 qop cmd2
| case exp of { calts }
cstmt :: = let decls
| pat <- cmd
| rec { cstmt1 .. cstmtn }
| cmd
New keywords and symbols:
proc rec
-< >- -<< >>-
(| |)
The do-notation in cmds was not described in Ross's ICFP'01 paper; instead
it's in his chapter in The Fun of Programming (Plagrave 2003).
The four arrow-tail forms (-<) etc cover
(a) which order the pices come in (-< vs >-), and
(b) whether the locally bound variables can be used in the
arrow part (-< vs -<<) .
In previous presentations, the higher-order-ness (b) was inferred,
but it makes a big difference to the typing required so it seems more
consistent to be explicit.
The 'rec' form is also available in do-notation:
* you can use 'rec' in an ordinary do, with the obvious meaning
* using 'mdo' just says "infer the minimal recs"
Still to do
~~~~~~~~~~~
Top priority is the user manual.
The implementation still lacks an implementation of
the case form of cmd.
Implementation notes
~~~~~~~~~~~~~~~~~~~~
Cmds are parsed, and indeed renamed, as expressions. The type checker
distinguishes the two.
Revision Changes Path
1.97 +39 -21 fptools/ghc/compiler/deSugar/DsExpr.lhs
1.42 +16 -13 fptools/ghc/compiler/deSugar/DsListComp.lhs
1.49 +26 -10 fptools/ghc/compiler/deSugar/DsMonad.lhs
1.71 +36 -1 fptools/ghc/compiler/deSugar/DsUtils.lhs
1.33 +4 -5 fptools/ghc/compiler/hsSyn/Convert.lhs
1.80 +181 -35 fptools/ghc/compiler/hsSyn/HsExpr.lhs
1.41 +5 -1 fptools/ghc/compiler/hsSyn/HsSyn.lhs
1.173 +1 -0 fptools/ghc/compiler/main/CmdLineOpts.lhs
1.117 +2 -1 fptools/ghc/compiler/main/DriverFlags.hs
1.182 +10 -12 fptools/ghc/compiler/main/HscMain.lhs
1.13 +1 -0 fptools/ghc/compiler/main/ParsePkgConf.y
1.92 +73 -34 fptools/ghc/compiler/parser/Lex.lhs
1.120 +48 -20 fptools/ghc/compiler/parser/Parser.y
1.56 +4 -0 fptools/ghc/compiler/parser/RdrHsSyn.lhs
1.76 +37 -0 fptools/ghc/compiler/prelude/PrelNames.lhs
1.166 +23 -10 fptools/ghc/compiler/rename/RnEnv.lhs
1.113 +300 -62 fptools/ghc/compiler/rename/RnExpr.lhs
1.81 +1 -0 fptools/ghc/compiler/rename/RnHiFiles.lhs
1.72 +2 -0 fptools/ghc/compiler/rename/RnHsSyn.lhs
1.119 +11 -11 fptools/ghc/compiler/typecheck/Inst.lhs
1.122 +48 -33 fptools/ghc/compiler/typecheck/TcEnv.lhs
1.156 +51 -42 fptools/ghc/compiler/typecheck/TcExpr.lhs
1.90 +60 -14 fptools/ghc/compiler/typecheck/TcHsSyn.lhs
1.47 +6 -1 fptools/ghc/compiler/typecheck/TcMType.lhs
1.77 +168 -157 fptools/ghc/compiler/typecheck/TcMatches.lhs
1.110 +1 -1 fptools/ghc/compiler/typecheck/TcMonoType.lhs
1.90 +3 -3 fptools/ghc/compiler/typecheck/TcPat.lhs
1.37 +34 -22 fptools/ghc/compiler/typecheck/TcRnDriver.lhs
1.18 +49 -13 fptools/ghc/compiler/typecheck/TcRnMonad.lhs
1.27 +67 -17 fptools/ghc/compiler/typecheck/TcRnTypes.lhs
1.47 +24 -17 fptools/ghc/compiler/typecheck/TcUnify.lhs
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc