[project @ 2003-06-24 07:58:18 by simonpj]
authorsimonpj <unknown>
Tue, 24 Jun 2003 07:58:27 +0000 (07:58 +0000)
committersimonpj <unknown>
Tue, 24 Jun 2003 07:58:27 +0000 (07:58 +0000)
commit16e4ce4c0c02650082f2e11982017c903c549ad5
tree660596d4caf0693a48051760d3cb8e7e24dc70b5
parent67d41f03f77eaf4d60f6c5e7599546fe2c847942
[project @ 2003-06-24 07:58:18 by simonpj]
----------------------------------------------
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.
33 files changed:
ghc/compiler/deSugar/DsArrows.lhs [new file with mode: 0644]
ghc/compiler/deSugar/DsExpr.lhs
ghc/compiler/deSugar/DsListComp.lhs
ghc/compiler/deSugar/DsMonad.lhs
ghc/compiler/deSugar/DsUtils.lhs
ghc/compiler/hsSyn/Convert.lhs
ghc/compiler/hsSyn/HsExpr.lhs
ghc/compiler/hsSyn/HsSyn.lhs
ghc/compiler/main/CmdLineOpts.lhs
ghc/compiler/main/DriverFlags.hs
ghc/compiler/main/HscMain.lhs
ghc/compiler/main/ParsePkgConf.y
ghc/compiler/parser/Lex.lhs
ghc/compiler/parser/Parser.y
ghc/compiler/parser/RdrHsSyn.lhs
ghc/compiler/prelude/PrelNames.lhs
ghc/compiler/rename/RnEnv.lhs
ghc/compiler/rename/RnExpr.lhs
ghc/compiler/rename/RnHiFiles.lhs
ghc/compiler/rename/RnHsSyn.lhs
ghc/compiler/typecheck/Inst.lhs
ghc/compiler/typecheck/TcArrows.lhs [new file with mode: 0644]
ghc/compiler/typecheck/TcEnv.lhs
ghc/compiler/typecheck/TcExpr.lhs
ghc/compiler/typecheck/TcHsSyn.lhs
ghc/compiler/typecheck/TcMType.lhs
ghc/compiler/typecheck/TcMatches.lhs
ghc/compiler/typecheck/TcMonoType.lhs
ghc/compiler/typecheck/TcPat.lhs
ghc/compiler/typecheck/TcRnDriver.lhs
ghc/compiler/typecheck/TcRnMonad.lhs
ghc/compiler/typecheck/TcRnTypes.lhs
ghc/compiler/typecheck/TcUnify.lhs