Add 'rec' to stmts in a 'do', and deprecate 'mdo'
authorsimonpj@microsoft.com <unknown>
Wed, 28 Oct 2009 13:35:54 +0000 (13:35 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 28 Oct 2009 13:35:54 +0000 (13:35 +0000)
commitf04dead93a15af1cb818172f207b8a81d2c81298
treef4643a3ad241a09abe524bacbbb0d09a3f752198
parent69f8ed93800605d8df011388450d6d3bb9ca6071
Add 'rec' to stmts in a 'do', and deprecate 'mdo'

The change is this (see Trac #2798).  Instead of writing

  mdo { a <- getChar
      ; b <- f c
      ; c <- g b
      ; putChar c
      ; return b }

you would write

  do { a <- getChar
     ; rec { b <- f c
           ; c <- g b }
     ; putChar c
     ; return b }

That is,
  * 'mdo' is eliminated
  * 'rec' is added, which groups a bunch of statements
    into a single recursive statement

This 'rec' thing is already present for the arrow notation, so it
makes the two more uniform.  Moreover, 'rec' lets you say more
precisely where the recursion is (if you want to), whereas 'mdo' just
says "there's recursion here somewhere".  Lastly, all this works with
rebindable syntax (which mdo does not).

Currently 'mdo' is enabled by -XRecursiveDo.  So we now deprecate this
flag, with another flag -XDoRec to enable the 'rec' keyword.

Implementation notes:
  * Some changes in Lexer.x
  * All uses of RecStmt now use record syntax

I'm still not really happy with the "rec_ids" and "later_ids" in the
RecStmt constructor, but I don't dare change it without consulting Ross
about the consequences for arrow syntax.
12 files changed:
compiler/deSugar/Coverage.lhs
compiler/deSugar/DsArrows.lhs
compiler/deSugar/DsExpr.lhs
compiler/hsSyn/HsExpr.lhs
compiler/hsSyn/HsUtils.lhs
compiler/main/DynFlags.hs
compiler/parser/Lexer.x
compiler/rename/RnExpr.lhs
compiler/typecheck/TcExpr.lhs-boot
compiler/typecheck/TcHsSyn.lhs
compiler/typecheck/TcMatches.lhs
docs/users_guide/glasgow_exts.xml