Merge branch monad-comp onto master
authorSimon Peyton Jones <simonpj@microsoft.com>
Wed, 4 May 2011 15:37:08 +0000 (16:37 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Wed, 4 May 2011 15:37:08 +0000 (16:37 +0100)
This patch implements monad comprehensions, Trac #4370.
Thanks to Nils Schweinsberg for doing most of the heavy lifting.

I did quite a lot of related refactoring as well.  Notably:

* Combined TransformStmt and GroupStmt into a single
  constructor TransStmt; they share a lot of code.
  I also made TransStmt into a record; it has a lot of fields.

* Remove the "result expression" field of HsDo, and instead
  implement LastStmt, which is expected to be at the end
  of a list of Stmts

* Generalise and tidy up the typechecking of monad comprehensions

* Do-notation in arrows is marked with HsStmtContext = ArrowExpr

* tcMDoStmt (which was only used for arrows) is moved
  to TcArrows, and renamed tcArrDoStmt

* Improved documentation in the user manual

* Lots of other minor changes

1  2 
compiler/deSugar/Check.lhs

@@@ -110,9 -110,11 +110,11 @@@ type EqnSet = UniqSet EqnN
  check :: [EquationInfo] -> ([ExhaustivePat], [EquationInfo])
    -- Second result is the shadowed equations
    -- if there are view patterns, just give up - don't know what the function is
- check qs = (untidy_warns, shadowed_eqns)
+ check qs = pprTrace "check" (ppr tidy_qs) $
+            (untidy_warns, shadowed_eqns)
        where
-       (warns, used_nos) = check' ([1..] `zip` map tidy_eqn qs)
+         tidy_qs = map tidy_eqn qs
+       (warns, used_nos) = check' ([1..] `zip` tidy_qs)
        untidy_warns = map untidy_exhaustive warns 
        shadowed_eqns = [eqn | (eqn,i) <- qs `zip` [1..], 
                                not (i `elementOfUniqSet` used_nos)]
@@@ -694,18 -696,18 +696,18 @@@ tidy_pat (TuplePat ps boxity ty
    where
      arity = length ps
  
 -tidy_pat (NPat lit mb_neg eq) = tidyNPat lit mb_neg eq
 +tidy_pat (NPat lit mb_neg eq) = tidyNPat tidy_lit_pat lit mb_neg eq
 +tidy_pat (LitPat lit)         = tidy_lit_pat lit
  
 --- Unpack string patterns fully, so we can see when they overlap with
 --- each other, or even explicit lists of Chars.
 -tidy_pat (LitPat lit)
 +tidy_lit_pat :: HsLit -> Pat Id
 +-- Unpack string patterns fully, so we can see when they 
 +-- overlap with each other, or even explicit lists of Chars.
 +tidy_lit_pat lit
    | HsString s <- lit
 -  = unLoc $ foldr (\c pat -> mkPrefixConPat consDataCon [mk_char_lit c, pat] stringTy)
 +  = unLoc $ foldr (\c pat -> mkPrefixConPat consDataCon [mkCharLitPat c, pat] stringTy)
                  (mkPrefixConPat nilDataCon [] stringTy) (unpackFS s)
    | otherwise
    = tidyLitPat lit 
 -  where
 -    mk_char_lit c = mkPrefixConPat charDataCon [nlLitPat (HsCharPrim c)] charTy
  
  -----------------
  tidy_con :: DataCon -> HsConPatDetails Id -> HsConPatDetails Id