[project @ 2003-10-09 11:58:39 by simonpj]
[ghc-hetmet.git] / ghc / compiler / deSugar / DsGRHSs.lhs
index e413c58..75c76d6 100644 (file)
@@ -11,16 +11,17 @@ module DsGRHSs ( dsGuarded, dsGRHSs ) where
 import {-# SOURCE #-} DsExpr  ( dsExpr, dsLet )
 import {-# SOURCE #-} Match   ( matchSinglePat )
 
-import HsSyn           ( Stmt(..), HsExpr(..), GRHSs(..), GRHS(..) )
-import TcHsSyn         ( TypecheckedGRHSs, TypecheckedPat, TypecheckedStmt )
-import CoreSyn         ( CoreExpr, Bind(..) )
+import HsSyn           ( Stmt(..), HsExpr(..), GRHSs(..), GRHS(..), HsMatchContext(..) )
+import TcHsSyn         ( TypecheckedGRHSs, TypecheckedPat, TypecheckedStmt, TypecheckedMatchContext )
+import CoreSyn         ( CoreExpr )
 import Type            ( Type )
 
 import DsMonad
 import DsUtils
+import Unique          ( Uniquable(..) )
 import PrelInfo                ( nON_EXHAUSTIVE_GUARDS_ERROR_ID )
-import Unique          ( otherwiseIdKey, trueDataConKey, hasKey, Uniquable(..) )
-import Outputable
+import TysWiredIn      ( trueDataConId )
+import PrelNames       ( otherwiseIdKey, hasKey )
 \end{code}
 
 @dsGuarded@ is used for both @case@ expressions and pattern bindings.
@@ -38,7 +39,7 @@ necessary.  The type argument gives the type of the @ei@.
 dsGuarded :: TypecheckedGRHSs -> DsM CoreExpr
 
 dsGuarded grhss
-  = dsGRHSs PatBindMatch [] grhss                              `thenDs` \ (err_ty, match_result) ->
+  = dsGRHSs PatBindRhs [] grhss                                `thenDs` \ (err_ty, match_result) ->
     mkErrorAppDs nON_EXHAUSTIVE_GUARDS_ERROR_ID err_ty ""      `thenDs` \ error_expr ->
     extractMatchResult match_result error_expr
 \end{code}
@@ -46,12 +47,12 @@ dsGuarded grhss
 In contrast, @dsGRHSs@ produces a @MatchResult@.
 
 \begin{code}
-dsGRHSs :: DsMatchKind -> [TypecheckedPat]     -- These are to build a MatchContext from
-       -> TypecheckedGRHSs                     -- Guarded RHSs
+dsGRHSs :: TypecheckedMatchContext -> [TypecheckedPat] -- These are to build a MatchContext from
+       -> TypecheckedGRHSs                             -- Guarded RHSs
        -> DsM (Type, MatchResult)
 
-dsGRHSs kind pats (GRHSs grhss binds (Just ty))
-  = mapDs (dsGRHS kind pats) grhss             `thenDs` \ match_results ->
+dsGRHSs kind pats (GRHSs grhss binds ty)
+  = mappM (dsGRHS kind pats) grhss             `thenDs` \ match_results ->
     let 
        match_result1 = foldr1 combineMatchResults match_results
        match_result2 = adjustMatchResultDs (dsLet binds) match_result1
@@ -75,17 +76,23 @@ matchGuard :: [TypecheckedStmt]     -- Guard
            -> DsMatchContext            -- Context
           -> DsM MatchResult
 
-matchGuard (ExprStmt expr locn : should_be_null) ctx 
+-- See comments with HsExpr.Stmt re what an ExprStmt means
+-- Here we must be in a guard context (not do-expression, nor list-comp)       
+
+matchGuard [ResultStmt expr locn] ctx 
   = putSrcLocDs locn (dsExpr expr)     `thenDs` \ core_expr ->
     returnDs (cantFailMatchResult core_expr)
 
+       -- ExprStmts must be guards
        -- Turn an "otherwise" guard is a no-op
-matchGuard (GuardStmt (HsVar v) _ : stmts) ctx
+matchGuard (ExprStmt (HsVar v) _ _ : stmts) ctx
   |  v `hasKey` otherwiseIdKey
-  || v `hasKey` trueDataConKey
+  || v `hasKey` getUnique trueDataConId        
+       -- trueDataConId doesn't have the same 
+       -- unique as trueDataCon
   = matchGuard stmts ctx
 
-matchGuard (GuardStmt expr locn : stmts) ctx
+matchGuard (ExprStmt expr _ locn : stmts) ctx
   = matchGuard stmts ctx               `thenDs` \ match_result ->
     putSrcLocDs locn (dsExpr expr)     `thenDs` \ pred_expr ->
     returnDs (mkGuardedMatchResult pred_expr match_result)