[project @ 2001-07-12 16:21:22 by simonpj]
authorsimonpj <unknown>
Thu, 12 Jul 2001 16:21:24 +0000 (16:21 +0000)
committersimonpj <unknown>
Thu, 12 Jul 2001 16:21:24 +0000 (16:21 +0000)
--------------------------------------------
Fix another bug in the squash-newtypes story.
--------------------------------------------

[This one was spotted by Marcin, and is now enshrined in test tc130.]

The desugarer straddles the boundary between the type checker and
Core, so it sometimes needs to look through newtypes/implicit parameters
and sometimes not.  This is really a bit painful, but I can't think of
a better way to do it.

The only simple way to fix things was to pass a bit more type
information in the HsExpr type, from the type checker to the desugarer.
That led to the non-local changes you can see.

On the way I fixed one other thing.  In various HsSyn constructors
there is a Type that is bogus (bottom) before the type checker, and
filled in with a real type by the type checker.  In one place it was
a (Maybe Type) which was Nothing before, and (Just ty) afterwards.
I've defined a type synonym HsTypes.PostTcType for this, and a named
bottom value HsTypes.placeHolderType to use when you want the bottom
value.

27 files changed:
ghc/compiler/deSugar/Check.lhs
ghc/compiler/deSugar/DsCCall.lhs
ghc/compiler/deSugar/DsExpr.lhs
ghc/compiler/deSugar/DsForeign.lhs
ghc/compiler/deSugar/DsGRHSs.lhs
ghc/compiler/deSugar/DsHsSyn.lhs
ghc/compiler/deSugar/DsListComp.lhs
ghc/compiler/deSugar/DsMonad.lhs
ghc/compiler/deSugar/DsUtils.lhs
ghc/compiler/deSugar/Match.lhs
ghc/compiler/deSugar/MatchCon.lhs
ghc/compiler/deSugar/MatchLit.lhs
ghc/compiler/hsSyn/HsExpr.lhs
ghc/compiler/hsSyn/HsLit.lhs
ghc/compiler/hsSyn/HsTypes.lhs
ghc/compiler/main/HscMain.lhs
ghc/compiler/parser/ParseUtil.lhs
ghc/compiler/parser/Parser.y
ghc/compiler/rename/RnExpr.lhs
ghc/compiler/typecheck/TcClassDcl.lhs
ghc/compiler/typecheck/TcExpr.lhs
ghc/compiler/typecheck/TcGenDeriv.lhs
ghc/compiler/typecheck/TcHsSyn.lhs
ghc/compiler/typecheck/TcMatches.lhs
ghc/compiler/typecheck/TcModule.lhs
ghc/compiler/typecheck/TcSimplify.lhs
ghc/compiler/types/Generics.lhs

index c777de5..0d8e76a 100644 (file)
@@ -11,9 +11,8 @@ module Check ( check , ExhaustivePat ) where
 
 
 import HsSyn           
-import TcHsSyn         ( TypecheckedPat )
+import TcHsSyn         ( TypecheckedPat, outPatType )
 import TcType          ( tcTyConAppTyCon, tcTyConAppArgs )
-import DsHsSyn         ( outPatType ) 
 import DsUtils         ( EquationInfo(..), MatchResult(..), EqnSet, 
                          CanItFail(..),  tidyLitPat, tidyNPat, 
                        )
index b7c6064..bdfa3c0 100644 (file)
@@ -25,12 +25,12 @@ import Maybes               ( maybeToBool )
 import ForeignCall     ( ForeignCall(..), CCallSpec(..), CCallTarget(..), Safety, CCallConv(..) )
 import DataCon         ( splitProductType_maybe, dataConSourceArity, dataConWrapId )
 import ForeignCall     ( ForeignCall, CCallTarget(..) )
-import TcType          ( isUnLiftedType, mkFunTys,
-                         tcSplitTyConApp_maybe, tyVarsOfType, mkForAllTys, isPrimitiveType,
-                         isUnLiftedType, mkFunTy, mkTyConApp, 
-                         tcEqType, isBoolTy, isUnitTy,
-                         Type
+
+import TcType          ( Type, isUnLiftedType, mkFunTys, mkFunTy,
+                         tyVarsOfType, mkForAllTys, mkTyConApp, 
+                         isBoolTy, isUnitTy, isPrimitiveType
                        )
+import Type            ( splitTyConApp_maybe, repType, eqType )        -- Sees the representation type
 import PrimOp          ( PrimOp(TouchOp) )
 import TysPrim         ( realWorldStatePrimTy,
                          byteArrayPrimTyCon, mutableByteArrayPrimTyCon,
@@ -152,6 +152,7 @@ unboxArg arg
                              prim_arg 
                             [(DEFAULT,[],body)])
 
+  -- Newtypes 
   -- Data types with a single constructor, which has a single, primitive-typed arg
   -- This deals with Int, Float etc
   | is_product_type && data_con_arity == 1 
@@ -179,7 +180,9 @@ unboxArg arg
   = getSrcLocDs `thenDs` \ l ->
     pprPanic "unboxArg: " (ppr l <+> ppr arg_ty)
   where
-    arg_ty                                     = exprType arg
+    arg_ty                                     = repType (exprType arg)
+       -- The repType looks through any newtype or 
+       -- implicit-parameter wrappings on the argument.  
     maybe_product_type                                 = splitProductType_maybe arg_ty
     is_product_type                            = maybeToBool maybe_product_type
     Just (_, _, data_con, data_con_arg_tys)    = maybe_product_type
@@ -187,7 +190,7 @@ unboxArg arg
     (data_con_arg_ty1 : _)                     = data_con_arg_tys
 
     (_ : _ : data_con_arg_ty3 : _) = data_con_arg_tys
-    maybe_arg3_tycon              = tcSplitTyConApp_maybe data_con_arg_ty3
+    maybe_arg3_tycon              = splitTyConApp_maybe data_con_arg_ty3
     Just (arg3_tycon,_)                   = maybe_arg3_tycon
 \end{code}
 
@@ -212,7 +215,7 @@ boxResult :: [Id] -> Type -> DsM (Type, CoreExpr -> CoreExpr)
 -- the call.  The arg_ids passed in are the Ids passed to the actual ccall.
 
 boxResult arg_ids result_ty
-  = case tcSplitTyConApp_maybe result_ty of
+  = case splitTyConApp_maybe result_ty of
 
        -- The result is IO t, so wrap the result in an IO constructor
        Just (io_tycon, [io_res_ty]) | io_tycon `hasKey` ioTyConKey
@@ -282,7 +285,7 @@ touchzh = mkPrimOpId TouchOp
 
 mkTouches []     s cont = returnDs (cont s)
 mkTouches (v:vs) s cont
-  | not (idType v `tcEqType` foreignObjPrimTy) = mkTouches vs s cont
+  | not (idType v `eqType` foreignObjPrimTy) = mkTouches vs s cont
   | otherwise = newSysLocalDs realWorldStatePrimTy `thenDs` \s' -> 
                mkTouches vs s' cont `thenDs` \ rest ->
                returnDs (Case (mkApps (Var touchzh) [Type foreignObjPrimTy, 
@@ -294,20 +297,22 @@ resultWrapper :: Type
                  CoreExpr -> CoreExpr) -- Wrapper for the result 
 resultWrapper result_ty
   -- Base case 1: primitive types
-  | isPrimitiveType result_ty
+  | isPrimitiveType result_ty_rep
   = (Just result_ty, \e -> e)
 
-  -- Base case 1: the unit type ()
-  | isUnitTy result_ty
+  -- Base case 2: the unit type ()
+  | isUnitTy result_ty_rep
   = (Nothing, \e -> Var unitDataConId)
 
-  | isBoolTy result_ty
+  -- Base case 3: the boolean type ()
+  | isBoolTy result_ty_rep
   = (Just intPrimTy, \e -> Case e (mkWildId intPrimTy)
                                  [(DEFAULT             ,[],Var trueDataConId ),
                                   (LitAlt (mkMachInt 0),[],Var falseDataConId)])
 
   -- Data types with a single constructor, which has a single arg
-  | is_product_type && data_con_arity == 1
+  | Just (_, tycon_arg_tys, data_con, data_con_arg_tys) <- splitProductType_maybe result_ty_rep,
+    dataConSourceArity data_con == 1
   = let
         (maybe_ty, wrapper)    = resultWrapper unwrapped_res_ty
        (unwrapped_res_ty : _) = data_con_arg_tys
@@ -318,8 +323,5 @@ resultWrapper result_ty
   | otherwise
   = pprPanic "resultWrapper" (ppr result_ty)
   where
-    maybe_product_type                                         = splitProductType_maybe result_ty
-    is_product_type                                    = maybeToBool maybe_product_type
-    Just (_, tycon_arg_tys, data_con, data_con_arg_tys) = maybe_product_type
-    data_con_arity                                     = dataConSourceArity data_con
+    result_ty_rep = repType result_ty
 \end{code}
index 997d565..d5d718f 100644 (file)
@@ -15,9 +15,16 @@ import HsSyn         ( failureFreePat,
                          Match(..), HsBinds(..), MonoBinds(..), 
                          mkSimpleMatch 
                        )
-import TcHsSyn         ( TypecheckedHsExpr, TypecheckedHsBinds, TypecheckedStmt )
+import TcHsSyn         ( TypecheckedHsExpr, TypecheckedHsBinds, TypecheckedStmt, outPatType )
+
+-- NB: The desugarer, which straddles the source and Core worlds, sometimes
+--     needs to see source types (newtypes etc), and sometimes not
+--     So WATCH OUT; check each use of split*Ty functions.
+-- Sigh.  This is a pain.
+
 import TcType          ( tcSplitAppTy, tcSplitFunTys, tcSplitTyConApp_maybe, tcTyConAppArgs,
                          isIntegerTy, tcSplitTyConApp, isUnLiftedType, Type )
+import Type            ( splitFunTys )
 import CoreSyn
 import CoreUtils       ( exprType, mkIfThenElse, bindNonRec )
 
@@ -161,7 +168,9 @@ dsExpr (SectionL expr op)
   = dsExpr op                                          `thenDs` \ core_op ->
     -- for the type of y, we need the type of op's 2nd argument
     let
-       (x_ty:y_ty:_, _) = tcSplitFunTys (exprType core_op)
+       (x_ty:y_ty:_, _) = splitFunTys (exprType core_op)
+       -- Must look through an implicit-parameter type; 
+       -- newtype impossible; hence Type.splitFunTys
     in
     dsExpr expr                                `thenDs` \ x_core ->
     newSysLocalDs x_ty                 `thenDs` \ x_id ->
@@ -175,7 +184,8 @@ dsExpr (SectionR op expr)
   = dsExpr op                  `thenDs` \ core_op ->
     -- for the type of x, we need the type of op's 2nd argument
     let
-       (x_ty:y_ty:_, _) = tcSplitFunTys (exprType core_op)
+       (x_ty:y_ty:_, _) = splitFunTys (exprType core_op)
+       -- See comment with SectionL
     in
     dsExpr expr                                `thenDs` \ y_core ->
     newSysLocalDs x_ty                 `thenDs` \ x_id ->
@@ -276,7 +286,7 @@ dsExpr (TyApp expr tys)
 \underline{\bf Various data construction things}
 %              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 \begin{code}
-dsExpr (ExplicitListOut ty xs)
+dsExpr (ExplicitList ty xs)
   = go xs
   where
     go []     = returnDs (mkNilExpr ty)
@@ -340,6 +350,8 @@ dsExpr (RecordConOut data_con con_expr rbinds)
   = dsExpr con_expr    `thenDs` \ con_expr' ->
     let
        (arg_tys, _) = tcSplitFunTys (exprType con_expr')
+       -- A newtype in the corner should be opaque; 
+       -- hence TcType.tcSplitFunTys
 
        mk_arg (arg_ty, lbl)
          = case [rhs | (sel_id,rhs,_) <- rbinds,
@@ -382,10 +394,10 @@ might do some argument-evaluation first; and may have to throw away some
 dictionaries.
 
 \begin{code}
-dsExpr (RecordUpdOut record_expr record_out_ty dicts [])
+dsExpr (RecordUpdOut record_expr record_in_ty record_out_ty dicts [])
   = dsExpr record_expr
 
-dsExpr (RecordUpdOut record_expr record_out_ty dicts rbinds)
+dsExpr (RecordUpdOut record_expr record_in_ty record_out_ty dicts rbinds)
   = getSrcLocDs                        `thenDs` \ src_loc ->
     dsExpr record_expr         `thenDs` \ record_expr' ->
 
@@ -393,9 +405,8 @@ dsExpr (RecordUpdOut record_expr record_out_ty dicts rbinds)
        -- necessary so that we don't lose sharing
 
     let
-       record_in_ty = exprType record_expr'
-       in_inst_tys  = tcTyConAppArgs record_in_ty
-       out_inst_tys = tcTyConAppArgs record_out_ty
+       in_inst_tys  = tcTyConAppArgs record_in_ty      -- Newtype opaque
+       out_inst_tys = tcTyConAppArgs record_out_ty     -- Newtype opaque
 
        mk_val_arg field old_arg_id 
          = case [rhs | (sel_id, rhs, _) <- rbinds, 
@@ -416,7 +427,7 @@ dsExpr (RecordUpdOut record_expr record_out_ty dicts rbinds)
            in
            returnDs (mkSimpleMatch [ConPat con record_in_ty [] [] (map VarPat arg_ids)]
                                    rhs
-                                   (Just record_out_ty)
+                                   record_out_ty
                                    src_loc)
     in
        -- Record stuff doesn't work for existentials
@@ -474,7 +485,6 @@ dsExpr (DictApp expr dicts) -- becomes a curried application
 #ifdef DEBUG
 -- HsSyn constructs that just shouldn't be here:
 dsExpr (HsDo _ _ _)        = panic "dsExpr:HsDo"
-dsExpr (ExplicitList _)            = panic "dsExpr:ExplicitList"
 dsExpr (ExprWithTySig _ _)  = panic "dsExpr:ExprWithTySig"
 dsExpr (ArithSeqIn _)      = panic "dsExpr:ArithSeqIn"
 #endif
@@ -511,13 +521,10 @@ dsDo do_or_lc stmts return_id then_id fail_id result_ty
          | otherwise = do_expr expr locn       `thenDs` \ expr2 ->
                        returnDs (mkApps (Var return_id) [Type b_ty, expr2])
 
-       go (ExprStmt expr locn : stmts)
+       go (ExprStmt expr a_ty locn : stmts)
          | is_do       -- Do expression
          = do_expr expr locn           `thenDs` \ expr2 ->
            go stmts                    `thenDs` \ rest  ->
-           let
-               (_, a_ty) = tcSplitAppTy (exprType expr2)  -- Must be of form (m a)
-           in
            newSysLocalDs a_ty          `thenDs` \ ignored_result_id ->
            returnDs (mkApps (Var then_id) [Type a_ty, Type b_ty, expr2, 
                                            Lam ignored_result_id rest])
@@ -540,19 +547,19 @@ dsDo do_or_lc stmts return_id then_id fail_id result_ty
          = putSrcLocDs locn $
            dsExpr expr            `thenDs` \ expr2 ->
            let
-               (_, a_ty)  = tcSplitAppTy (exprType expr2) -- Must be of form (m a)
+               a_ty       = outPatType pat
                fail_expr  = HsApp (TyApp (HsVar fail_id) [b_ty])
                                    (HsLit (HsString (_PK_ msg)))
                msg = "Pattern match failure in do expression, " ++ showSDoc (ppr locn)
                main_match = mkSimpleMatch [pat] 
                                           (HsDoOut do_or_lc stmts return_id then_id
                                                     fail_id result_ty locn)
-                                          (Just result_ty) locn
+                                          result_ty locn
                the_matches
                  | failureFreePat pat = [main_match]
                  | otherwise          =
                      [ main_match
-                     , mkSimpleMatch [WildPat a_ty] fail_expr (Just result_ty) locn
+                     , mkSimpleMatch [WildPat a_ty] fail_expr result_ty locn
                      ]
            in
            matchWrapper (DoCtxt do_or_lc) the_matches  `thenDs` \ (binders, matching_code) ->
index 2d4d539..5017aa2 100644 (file)
@@ -27,19 +27,22 @@ import Name         ( mkGlobalName, nameModule, nameOccName, getOccString,
                          mkForeignExportOcc, isLocalName,
                          NamedThing(..),
                        )
-import TcType          ( tcSplitTyConApp_maybe, tcFunResultTy,
-                         tcSplitFunTys, tcSplitForAllTys,
+
+       -- Import Type not TcType; in this module we are generating code
+       -- to marshal representation types across to C
+import Type            ( splitTyConApp_maybe, funResultTy,
+                         splitFunTys, splitForAllTys, splitAppTy, 
                          Type, mkFunTys, mkForAllTys, mkTyConApp,
-                         mkFunTy, tcSplitAppTy, applyTy, tcEqType, isUnitTy
+                         mkFunTy, applyTy, eqType, repType
                        )
-import Type            ( repType )
+
 import ForeignCall     ( ForeignCall(..), CCallSpec(..), 
                          Safety(..), playSafe,
                          CExportSpec(..),
                          CCallConv(..), ccallConvToInt
                        )
 import CStrings                ( CLabelString )
-import TysWiredIn      ( addrTy, stablePtrTyCon )
+import TysWiredIn      ( addrTy, unitTy, stablePtrTyCon )
 import TysPrim         ( addrPrimTy )
 import PrelNames       ( hasKey, ioTyConKey, deRefStablePtrName, newStablePtrName,
                          bindIOName, returnIOName
@@ -120,7 +123,7 @@ dsFImport :: Module
          -> FoImport
          -> DsM ([Binding], SDoc, SDoc)
 dsFImport mod_name lbl_id (LblImport ext_nm) 
- = ASSERT(fromJust res_ty `tcEqType` addrPrimTy) -- typechecker ensures this
+ = ASSERT(fromJust res_ty `eqType` addrPrimTy) -- typechecker ensures this
    returnDs ([(lbl_id, rhs)], empty, empty)
  where
    (res_ty, fo_rhs) = resultWrapper (idType lbl_id)
@@ -142,8 +145,8 @@ dsFImport mod_name fn_id (CDynImport cconv) = dsFExportDynamic mod_name fn_id cc
 dsFCall mod_Name fn_id fcall
   = let
        ty                   = idType fn_id
-       (tvs, fun_ty)        = tcSplitForAllTys ty
-       (arg_tys, io_res_ty) = tcSplitFunTys fun_ty
+       (tvs, fun_ty)        = splitForAllTys ty
+       (arg_tys, io_res_ty) = splitFunTys fun_ty
     in
     newSysLocalsDs arg_tys                     `thenDs` \ args ->
     mapAndUnzipDs unboxArg (map Var args)      `thenDs` \ (val_args, arg_wrappers) ->
@@ -217,7 +220,7 @@ dsFExport mod_name fn_id ty ext_name cconv isDyn
        -- Look at the result type of the exported function, orig_res_ty
        -- If it's IO t, return         (\x.x,          IO t, t)
        -- If it's plain t, return      (\x.returnIO x, IO t, t)
-     (case tcSplitTyConApp_maybe orig_res_ty of
+     (case splitTyConApp_maybe orig_res_ty of
        Just (ioTyCon, [res_ty])
              -> ASSERT( ioTyCon `hasKey` ioTyConKey )
                        -- The function already returns IO t
@@ -226,7 +229,7 @@ dsFExport mod_name fn_id ty ext_name cconv isDyn
        other ->        -- The function returns t, so wrap the call in returnIO
                 dsLookupGlobalValue returnIOName       `thenDs` \ retIOId ->
                 returnDs (\body -> mkApps (Var retIOId) [Type orig_res_ty, body],
-                          tcFunResultTy (applyTy (idType retIOId) orig_res_ty), 
+                          funResultTy (applyTy (idType retIOId) orig_res_ty), 
                                -- We don't have ioTyCon conveniently to hand
                           orig_res_ty)
 
@@ -294,11 +297,11 @@ dsFExport mod_name fn_id ty ext_name cconv isDyn
      returnDs (f_helper_glob, (f_helper_glob, the_body), h_stub, c_stub)
 
   where
-   (tvs,sans_foralls)          = tcSplitForAllTys ty
-   (fe_arg_tys', orig_res_ty)  = tcSplitFunTys sans_foralls
+   (tvs,sans_foralls)          = splitForAllTys ty
+   (fe_arg_tys', orig_res_ty)  = splitFunTys sans_foralls
 
-   (_, stbl_ptr_ty')           = tcSplitForAllTys stbl_ptr_ty
-   (_, stbl_ptr_to_ty)         = tcSplitAppTy stbl_ptr_ty'
+   (_, stbl_ptr_ty')           = splitForAllTys stbl_ptr_ty
+   (_, stbl_ptr_to_ty)         = splitAppTy stbl_ptr_ty'
 
    fe_arg_tys | isDyn    = tail fe_arg_tys'
              | otherwise = fe_arg_tys'
@@ -389,9 +392,9 @@ dsFExportDynamic mod_name id cconv
 
  where
   ty                              = idType id
-  (tvs,sans_foralls)              = tcSplitForAllTys ty
-  ([arg_ty], io_res_ty)                   = tcSplitFunTys sans_foralls
-  Just (ioTyCon, [res_ty])        = tcSplitTyConApp_maybe io_res_ty
+  (tvs,sans_foralls)              = splitForAllTys ty
+  ([arg_ty], io_res_ty)                   = splitFunTys sans_foralls
+  Just (ioTyCon, [res_ty])        = splitTyConApp_maybe io_res_ty
   export_ty                       = mkFunTy (mkTyConApp stablePtrTyCon [arg_ty]) arg_ty
 
 toCName :: Id -> String
@@ -448,7 +451,7 @@ fexportEntry mod_nm c_nm helper args res_ty cc isDyn = (header_bits, c_bits)
 
   cParamTypes  = map showStgType real_args
 
-  res_ty_is_unit = isUnitTy res_ty
+  res_ty_is_unit = res_ty `eqType` unitTy
 
   cResType | res_ty_is_unit = text "void"
           | otherwise      = showStgType res_ty
@@ -496,7 +499,7 @@ showStgType t = text "Hs" <> text (showFFIType t)
 showFFIType :: Type -> String
 showFFIType t = getOccString (getName tc)
  where
-  tc = case tcSplitTyConApp_maybe (repType t) of
+  tc = case splitTyConApp_maybe (repType t) of
            Just (tc,_) -> tc
            Nothing     -> pprPanic "showFFIType" (ppr t)
 \end{code}
index 3f79cf8..0e562e5 100644 (file)
@@ -14,7 +14,7 @@ import {-# SOURCE #-} Match   ( matchSinglePat )
 import HsSyn           ( Stmt(..), HsExpr(..), GRHSs(..), GRHS(..), HsMatchContext(..) )
 import TcHsSyn         ( TypecheckedGRHSs, TypecheckedPat, TypecheckedStmt, TypecheckedMatchContext )
 import CoreSyn         ( CoreExpr )
-import TcType          ( Type )
+import Type            ( Type )
 
 import DsMonad
 import DsUtils
@@ -49,7 +49,7 @@ dsGRHSs :: TypecheckedMatchContext -> [TypecheckedPat]        -- These are to build a M
        -> TypecheckedGRHSs                             -- Guarded RHSs
        -> DsM (Type, MatchResult)
 
-dsGRHSs kind pats (GRHSs grhss binds (Just ty))
+dsGRHSs kind pats (GRHSs grhss binds ty)
   = mapDs (dsGRHS kind pats) grhss             `thenDs` \ match_results ->
     let 
        match_result1 = foldr1 combineMatchResults match_results
@@ -83,12 +83,12 @@ matchGuard [ResultStmt expr locn] ctx
 
        -- ExprStmts must be guards
        -- Turn an "otherwise" guard is a no-op
-matchGuard (ExprStmt (HsVar v) _ : stmts) ctx
+matchGuard (ExprStmt (HsVar v) _ _ : stmts) ctx
   |  v `hasKey` otherwiseIdKey
   || v `hasKey` trueDataConKey
   = matchGuard stmts ctx
 
-matchGuard (ExprStmt 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)
index 43bb8c7..9eee750 100644 (file)
@@ -13,64 +13,6 @@ import TcHsSyn               ( TypecheckedPat,
                          TypecheckedMonoBinds )
 
 import Id              ( idType, Id )
-import TcType           ( Type )
-import TysWiredIn      ( mkListTy, mkTupleTy, unitTy )
-import BasicTypes      ( Boxity(..) )
+import Type            ( Type )
 \end{code}
 
-Note: If @outPatType@ doesn't bear a strong resemblance to @exprType@,
-then something is wrong.
-\begin{code}
-outPatType :: TypecheckedPat -> Type
-
-outPatType (WildPat ty)                = ty
-outPatType (VarPat var)                = idType var
-outPatType (LazyPat pat)       = outPatType pat
-outPatType (AsPat var pat)     = idType var
-outPatType (ConPat _ ty _ _ _) = ty
-outPatType (ListPat ty _)      = mkListTy ty
-outPatType (TuplePat pats box) = mkTupleTy box (length pats) (map outPatType pats)
-outPatType (RecPat _ ty _ _ _)  = ty
-outPatType (LitPat lit ty)     = ty
-outPatType (NPat lit ty _)     = ty
-outPatType (NPlusKPat _ _ ty _ _) = ty
-outPatType (DictPat ds ms)      = case (length ds_ms) of
-                                   0 -> unitTy
-                                   1 -> idType (head ds_ms)
-                                   n -> mkTupleTy Boxed n (map idType ds_ms)
-                                  where
-                                   ds_ms = ds ++ ms
-\end{code}
-
-
-Nota bene: @DsBinds@ relies on the fact that at least for simple
-tuple patterns @collectTypedPatBinders@ returns the binders in
-the same order as they appear in the tuple.
-
-@collectTypedBinders@ and @collectedTypedPatBinders@ are the exportees.
-
-\begin{code}
-collectTypedMonoBinders :: TypecheckedMonoBinds -> [Id]
-collectTypedMonoBinders EmptyMonoBinds         = []
-collectTypedMonoBinders (PatMonoBind pat _ _)   = collectTypedPatBinders pat
-collectTypedMonoBinders (FunMonoBind f _ _ _)   = [f]
-collectTypedMonoBinders (VarMonoBind v _)       = [v]
-collectTypedMonoBinders (CoreMonoBind v _)      = [v]
-collectTypedMonoBinders (AndMonoBinds bs1 bs2)
- = collectTypedMonoBinders bs1 ++ collectTypedMonoBinders bs2
-collectTypedMonoBinders (AbsBinds _ _ exports _ _)
-  = [global | (_, global, local) <- exports]
-
-collectTypedPatBinders :: TypecheckedPat -> [Id]
-collectTypedPatBinders (VarPat var)           = [var]
-collectTypedPatBinders (LazyPat pat)          = collectTypedPatBinders pat
-collectTypedPatBinders (AsPat a pat)          = a : collectTypedPatBinders pat
-collectTypedPatBinders (ConPat _ _ _ _ pats)   = concat (map collectTypedPatBinders pats)
-collectTypedPatBinders (ListPat t pats)        = concat (map collectTypedPatBinders pats)
-collectTypedPatBinders (TuplePat pats _)       = concat (map collectTypedPatBinders pats)
-collectTypedPatBinders (RecPat _ _ _ _ fields) = concat (map (\ (f,pat,_) -> collectTypedPatBinders pat)
-                                                         fields)
-collectTypedPatBinders (DictPat ds ms)        = ds ++ ms
-collectTypedPatBinders (NPlusKPat var _ _ _ _) = [var]
-collectTypedPatBinders any_other_pat          = [ {-no binders-} ]
-\end{code}
index 2216ae0..ebe08c6 100644 (file)
@@ -12,8 +12,7 @@ import {-# SOURCE #-} DsExpr ( dsExpr, dsLet )
 
 import BasicTypes      ( Boxity(..) )
 import HsSyn           ( OutPat(..), HsExpr(..), Stmt(..), HsMatchContext(..), HsDoContext(..) )
-import TcHsSyn         ( TypecheckedStmt, TypecheckedPat, TypecheckedHsExpr )
-import DsHsSyn         ( outPatType )
+import TcHsSyn         ( TypecheckedStmt, TypecheckedPat, TypecheckedHsExpr, outPatType )
 import CoreSyn
 
 import DsMonad         -- the monadery used in the desugarer
@@ -23,7 +22,7 @@ import CmdLineOpts    ( opt_FoldrBuildOn )
 import CoreUtils       ( exprType, mkIfThenElse )
 import Id              ( idType )
 import Var              ( Id )
-import TcType          ( mkTyVarTy, mkFunTys, mkFunTy, Type )
+import Type            ( mkTyVarTy, mkFunTys, mkFunTy, Type )
 import TysPrim         ( alphaTyVar )
 import TysWiredIn      ( nilDataCon, consDataCon, unitDataConId, mkListTy, mkTupleTy )
 import Match           ( matchSimply )
@@ -158,7 +157,7 @@ deListComp [ResultStmt expr locn] list      -- Figure 7.4, SLPJ, p 135, rule C above
     returnDs (mkConsExpr (exprType core_expr) core_expr list)
 
        -- Non-last: must be a guard
-deListComp (ExprStmt guard locn : quals) list  -- rule B above
+deListComp (ExprStmt guard ty locn : quals) list       -- rule B above
   = dsExpr guard                       `thenDs` \ core_guard ->
     deListComp quals list      `thenDs` \ core_rest ->
     returnDs (mkIfThenElse core_guard core_rest list)
@@ -280,7 +279,7 @@ dfListComp c_id n_id [ResultStmt expr locn]
     returnDs (mkApps (Var c_id) [core_expr, Var n_id])
 
        -- Non-last: must be a guard
-dfListComp c_id n_id (ExprStmt guard locn  : quals)
+dfListComp c_id n_id (ExprStmt guard ty locn  : quals)
   = dsExpr guard                                       `thenDs` \ core_guard ->
     dfListComp c_id n_id quals `thenDs` \ core_rest ->
     returnDs (mkIfThenElse core_guard core_rest (Var n_id))
index 9868a37..6fc4aa7 100644 (file)
@@ -33,7 +33,7 @@ import Module         ( Module )
 import Var             ( TyVar, setTyVarUnique )
 import Outputable
 import SrcLoc          ( noSrcLoc, SrcLoc )
-import TcType           ( Type )
+import Type             ( Type )
 import UniqSupply      ( initUs_, splitUniqSupply, uniqFromSupply, uniqsFromSupply,
                          UniqSM, UniqSupply )
 import Unique          ( Unique )
index 270c896..008cebf 100644 (file)
@@ -33,8 +33,7 @@ module DsUtils (
 import {-# SOURCE #-} Match ( matchSimply )
 
 import HsSyn
-import TcHsSyn         ( TypecheckedPat )
-import DsHsSyn         ( outPatType, collectTypedPatBinders )
+import TcHsSyn         ( TypecheckedPat, outPatType, collectTypedPatBinders )
 import CoreSyn
 
 import DsMonad
@@ -46,8 +45,8 @@ import Id             ( idType, Id, mkWildId )
 import Literal         ( Literal(..), inIntRange, tARGET_MAX_INT )
 import TyCon           ( isNewTyCon, tyConDataCons, isRecursiveTyCon )
 import DataCon         ( DataCon, dataConStrictMarks, dataConId )
-import TcType          ( mkFunTy, isUnLiftedType, Type )
-import TcType          ( tcSplitTyConApp, isIntTy, isFloatTy, isDoubleTy )
+import Type            ( mkFunTy, isUnLiftedType, Type )
+import TcType          ( tcTyConAppTyCon, isIntTy, isFloatTy, isDoubleTy )
 import TysPrim         ( intPrimTy, charPrimTy, floatPrimTy, doublePrimTy )
 import TysWiredIn      ( nilDataCon, consDataCon, 
                           tupleCon,
@@ -269,8 +268,8 @@ mkCoAlgCaseMatchResult var match_alts
   = MatchResult fail_flag mk_case
   where
        -- Common stuff
-    scrut_ty    = idType var
-    (tycon, _)  = tcSplitTyConApp scrut_ty             -- Newtypes must be opaque here
+    scrut_ty = idType var
+    tycon    = tcTyConAppTyCon scrut_ty                -- Newtypes must be opaque here
 
        -- Stuff for newtype
     (_, arg_ids, match_result) = head match_alts
@@ -620,4 +619,3 @@ mkFailurePair expr
 \end{code}
 
 
-
index 5aa3fdc..e56a8ab 100644 (file)
@@ -10,8 +10,7 @@ module Match ( match, matchExport, matchWrapper, matchSimply, matchSinglePat ) w
 
 import CmdLineOpts     ( DynFlag(..), dopt )
 import HsSyn           
-import TcHsSyn         ( TypecheckedPat, TypecheckedMatch, TypecheckedMatchContext )
-import DsHsSyn         ( outPatType )
+import TcHsSyn         ( TypecheckedPat, TypecheckedMatch, TypecheckedMatchContext, outPatType )
 import Check            ( check, ExhaustivePat )
 import CoreSyn
 import CoreUtils       ( bindNonRec )
@@ -23,7 +22,7 @@ import DataCon                ( dataConFieldLabels, dataConInstOrigArgTys )
 import MatchCon                ( matchConFamily )
 import MatchLit                ( matchLiterals )
 import PrelInfo                ( pAT_ERROR_ID )
-import TcType          ( mkTyVarTys, Type, tcSplitTyConApp, tcEqType )
+import TcType          ( mkTyVarTys, Type, tcTyConAppArgs, tcEqType )
 import TysWiredIn      ( nilDataCon, consDataCon, mkTupleTy, mkListTy, tupleCon )
 import BasicTypes      ( Boxity(..) )
 import UniqSet
@@ -416,7 +415,7 @@ tidy1 v (RecPat data_con pat_ty ex_tvs dicts rpats) match_result
     pats            = map mk_pat tagged_arg_tys
 
        -- Boring stuff to find the arg-tys of the constructor
-    (_, inst_tys)    = tcSplitTyConApp pat_ty
+    inst_tys         = tcTyConAppArgs pat_ty   -- Newtypes must be opaque
     con_arg_tys'     = dataConInstOrigArgTys data_con (inst_tys ++ mkTyVarTys ex_tvs)
     tagged_arg_tys   = con_arg_tys' `zip` (dataConFieldLabels data_con)
 
index 4795fdb..4094342 100644 (file)
@@ -17,7 +17,7 @@ import DsUtils
 
 import Id              ( Id )
 import CoreSyn
-import TcType          ( mkTyVarTys )
+import Type            ( mkTyVarTys )
 import ListSetOps      ( equivClassesByUniq )
 import Unique          ( Uniquable(..) )
 \end{code}
index 2bea106..308ca8f 100644 (file)
@@ -21,7 +21,7 @@ import DsUtils
 
 import Literal         ( mkMachInt, Literal(..) )
 import Maybes          ( catMaybes )
-import TcType          ( isUnLiftedType )
+import Type            ( isUnLiftedType )
 import Panic           ( panic, assertPanic )
 \end{code}
 
index d036547..b7d4573 100644 (file)
@@ -10,6 +10,7 @@ module HsExpr where
 
 -- friends:
 import HsBinds         ( HsBinds(..), nullBinds )
+import HsTypes         ( PostTcType )
 import HsLit           ( HsLit, HsOverLit )
 import BasicTypes      ( Fixity(..) )
 import HsTypes         ( HsType )
@@ -95,9 +96,7 @@ data HsExpr id pat
                SrcLoc
 
   | ExplicitList               -- syntactic list
-               [HsExpr id pat]
-  | ExplicitListOut            -- TRANSLATION
-               Type    -- Gives type of components of list
+               PostTcType      -- Gives type of components of list
                [HsExpr id pat]
 
   | ExplicitTuple              -- tuple
@@ -122,8 +121,9 @@ data HsExpr id pat
                (HsRecordBinds id pat)
 
   | RecordUpdOut (HsExpr id pat)       -- TRANSLATION
+                Type                   -- Type of *input* record
                 Type                   -- Type of *result* record (may differ from
-                                               -- type of input record)
+                                       --      type of input record)
                 [id]                   -- Dicts needed for construction
                 (HsRecordBinds id pat)
 
@@ -146,7 +146,7 @@ data HsExpr id pat
                                -- NOTE: this CCall is the *boxed*
                                -- version; the desugarer will convert
                                -- it into the unboxed "ccall#".
-               Type    -- The result type; will be *bottom*
+               PostTcType      -- The result type; will be *bottom*
                                -- until the typechecker gets ahold of it
 
   | HsSCC      FAST_STRING     -- "set cost centre" (_scc_) annotation
@@ -300,9 +300,7 @@ ppr_expr (HsWith expr binds)
 ppr_expr (HsDo do_or_list_comp stmts _)            = pprDo do_or_list_comp stmts
 ppr_expr (HsDoOut do_or_list_comp stmts _ _ _ _ _) = pprDo do_or_list_comp stmts
 
-ppr_expr (ExplicitList exprs)
-  = brackets (fsep (punctuate comma (map ppr_expr exprs)))
-ppr_expr (ExplicitListOut ty exprs)
+ppr_expr (ExplicitList _ exprs)
   = brackets (fsep (punctuate comma (map ppr_expr exprs)))
 
 ppr_expr (ExplicitTuple exprs boxity)
@@ -315,7 +313,7 @@ ppr_expr (RecordConOut data_con con rbinds)
 
 ppr_expr (RecordUpd aexp rbinds)
   = pp_rbinds (pprParendExpr aexp) rbinds
-ppr_expr (RecordUpdOut aexp _ _ rbinds)
+ppr_expr (RecordUpdOut aexp _ _ _ rbinds)
   = pp_rbinds (pprParendExpr aexp) rbinds
 
 ppr_expr (ExprWithTySig expr sig)
@@ -381,8 +379,7 @@ pprParendExpr expr
 
       HsVar _              -> pp_as_was
       HsIPVar _                    -> pp_as_was
-      ExplicitList _       -> pp_as_was
-      ExplicitListOut _ _   -> pp_as_was
+      ExplicitList _ _      -> pp_as_was
       ExplicitTuple _ _            -> pp_as_was
       HsPar _              -> pp_as_was
 
@@ -449,7 +446,7 @@ data Match id pat
 data GRHSs id pat      
   = GRHSs [GRHS id pat]                -- Guarded RHSs
          (HsBinds id pat)      -- The where clause
-         (Maybe Type)          -- Just rhs_ty after type checking
+         PostTcType            -- Type of RHS (after type checking)
 
 data GRHS id pat
   = GRHS  [Stmt id pat]                -- The RHS is the final ResultStmt
@@ -457,9 +454,9 @@ data GRHS id pat
                                -- it printed 'wrong' in error messages 
          SrcLoc
 
-mkSimpleMatch :: [pat] -> HsExpr id pat -> Maybe Type -> SrcLoc -> Match id pat
-mkSimpleMatch pats rhs maybe_rhs_ty locn
-  = Match [] pats Nothing (GRHSs (unguardedRHS rhs locn) EmptyBinds maybe_rhs_ty)
+mkSimpleMatch :: [pat] -> HsExpr id pat -> Type -> SrcLoc -> Match id pat
+mkSimpleMatch pats rhs rhs_ty locn
+  = Match [] pats Nothing (GRHSs (unguardedRHS rhs locn) EmptyBinds rhs_ty)
 
 unguardedRHS :: HsExpr id pat -> SrcLoc -> [GRHS id pat]
 unguardedRHS rhs loc = [GRHS [ResultStmt rhs loc] loc]
@@ -508,7 +505,7 @@ pprMatch ctxt (Match _ pats maybe_ty grhss)
 
 pprGRHSs :: (Outputable id, Outputable pat)
         => HsMatchContext id -> GRHSs id pat -> SDoc
-pprGRHSs ctxt (GRHSs grhss binds maybe_ty)
+pprGRHSs ctxt (GRHSs grhss binds ty)
   = vcat (map (pprGRHS ctxt) grhss)
     $$
     (if nullBinds binds then empty
@@ -542,11 +539,12 @@ pp_rhs ctxt rhs = ptext (matchSeparator ctxt) <+> pprDeeper (ppr rhs)
 data Stmt id pat
   = BindStmt   pat (HsExpr id pat) SrcLoc
   | LetStmt    (HsBinds id pat)
-  | ResultStmt (HsExpr id pat) SrcLoc  -- See notes that follow
-  | ExprStmt   (HsExpr id pat) SrcLoc  -- See notes that follow
-  | ParStmt    [[Stmt id pat]]         -- List comp only: parallel set of quals
-  | ParStmtOut [([id], [Stmt id pat])] -- PLC after renaming; the ids are the binders
-                                       -- bound by the stmts
+  | ResultStmt (HsExpr id pat) SrcLoc                  -- See notes that follow
+  | ExprStmt   (HsExpr id pat) PostTcType SrcLoc       -- See notes that follow
+       -- The type is the *element type* of the expression
+  | ParStmt    [[Stmt id pat]]                         -- List comp only: parallel set of quals
+  | ParStmtOut [([id], [Stmt id pat])]                 -- PLC after renaming; the ids are the binders
+                                                       -- bound by the stmts
 \end{code}
 
 ExprStmts and ResultStmts are a bit tricky, because what they mean
@@ -554,7 +552,7 @@ depends on the context.  Consider the following contexts:
 
        A do expression of type (m res_ty)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-       * ExprStmt E:   do { ....; E; ... }
+       * ExprStmt E any_ty:   do { ....; E; ... }
                E :: m any_ty
          Translation: E >> ...
        
@@ -564,7 +562,7 @@ depends on the context.  Consider the following contexts:
        
        A list comprehensions of type [elt_ty]
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-       * ExprStmt E:   [ .. | .... E ]
+       * ExprStmt E Bool:   [ .. | .... E ]
                        [ .. | ..., E, ... ]
                        [ .. | .... | ..., E | ... ]
                E :: Bool
@@ -576,7 +574,7 @@ depends on the context.  Consider the following contexts:
        
        A guard list, guarding a RHS of type rhs_ty
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-       * ExprStmt E:   f x | ..., E, ... = ...rhs...
+       * ExprStmt E Bool:   f x | ..., E, ... = ...rhs...
                E :: Bool
          Translation: if E then fail else ...
        
@@ -598,7 +596,7 @@ instance (Outputable id, Outputable pat) =>
 
 pprStmt (BindStmt pat expr _) = hsep [ppr pat, ptext SLIT("<-"), ppr expr]
 pprStmt (LetStmt binds)       = hsep [ptext SLIT("let"), pprBinds binds]
-pprStmt (ExprStmt expr _)     = ppr expr
+pprStmt (ExprStmt expr _ _)   = ppr expr
 pprStmt (ResultStmt expr _)   = ppr expr
 pprStmt (ParStmt stmtss)
  = hsep (map (\stmts -> ptext SLIT("| ") <> ppr stmts) stmtss)
index 2e33073..39d737d 100644 (file)
@@ -8,7 +8,8 @@ module HsLit where
 
 #include "HsVersions.h"
 
-import Type    ( Type )        
+import Type    ( Type )
+import HsTypes ( PostTcType )
 import Outputable
 import Ratio   ( Rational )
 \end{code}
@@ -34,9 +35,9 @@ data HsLit
   | HsRat          Rational Type       -- Genuinely a rational; arises only from TRANSLATION
   | HsFloatPrim            Rational            -- Unboxed Float
   | HsDoublePrim    Rational           -- Unboxed Double
-  | HsLitLit       FAST_STRING Type    -- to pass ``literal literals'' through to C
-                                       -- also: "overloaded" type; but
-                                       -- must resolve to boxed-primitive!
+  | HsLitLit       FAST_STRING PostTcType      -- to pass ``literal literals'' through to C
+                                               -- also: "overloaded" type; but
+                                               -- must resolve to boxed-primitive!
        -- The Type in HsLitLit is needed when desuaring;
        -- before the typechecker it's just an error value
 
index 959bcd7..b6f2a8d 100644 (file)
@@ -11,7 +11,10 @@ module HsTypes (
         , hsUsOnce, hsUsMany
 
        , mkHsForAllTy, mkHsDictTy, mkHsIParamTy
-       , hsTyVarName, hsTyVarNames, replaceTyVarName
+       , hsTyVarName, hsTyVarNames, replaceTyVarName,
+       
+       -- Type place holder
+       PostTcType, placeHolderType,
 
        -- Printing
        , pprParendHsType, pprHsForAll, pprHsContext, pprHsTyVarBndr
@@ -44,9 +47,32 @@ import PrelNames     ( mkTupConRdrName, listTyConKey, usOnceTyConKey, usManyTyConKey
                        )
 import FiniteMap
 import Outputable
+\end{code}
+
+
+%************************************************************************
+%*                                                                     *
+\subsection{Annotating the syntax}
+%*                                                                     *
+%************************************************************************
 
+\begin{code}
+type PostTcType = Type         -- Used for slots in the abstract syntax
+                               -- where we want to keep slot for a type
+                               -- to be added by the type checker...but
+                               -- before typechecking it's just bogus
+
+placeHolderType :: PostTcType  -- Used before typechecking
+placeHolderType  = panic "Evaluated the place holder for a PostTcType"
 \end{code}
 
+
+%************************************************************************
+%*                                                                     *
+\subsection{Data types}
+%*                                                                     *
+%************************************************************************
+
 This is the syntax for types as seen in type signatures.
 
 \begin{code}
index 04e023e..bab8b9a 100644 (file)
@@ -492,8 +492,8 @@ hscStmt dflags hst hit pcs0 icontext stmt just_expr
             Nothing -> return (pcs0, Nothing)
             Just parsed_stmt -> do {
 
-          let { notExprStmt (ExprStmt _ _) = False;
-                notExprStmt _              = True 
+          let { notExprStmt (ExprStmt _ _ _) = False;
+                notExprStmt _                = True 
               };
 
           if (just_expr && notExprStmt parsed_stmt)
@@ -513,7 +513,7 @@ hscStmt dflags hst hit pcs0 icontext stmt just_expr
                -- Typecheck it
          maybe_tc_return <- 
            if just_expr 
-               then case rn_stmt of { (syn, ExprStmt e _, decls) -> 
+               then case rn_stmt of { (syn, ExprStmt e _ _, decls) -> 
                     typecheckExpr dflags pcs1 hst type_env
                           print_unqual iNTERACTIVE (syn,e,decls) }
                else typecheckStmt dflags pcs1 hst type_env
index 7334806..1f8a1f1 100644 (file)
@@ -6,7 +6,6 @@
 \begin{code}
 module ParseUtil (
          parseError            -- String -> Pa
-       , cbot                  -- a
        , mkVanillaCon, mkRecCon,
 
        , mkRecConstrOrUpdate   -- HsExp -> [HsFieldUpdate] -> P HsExp
@@ -52,7 +51,6 @@ parseError s =
   getSrcLocP `thenP` \ loc ->
   failMsgP (hcat [ppr loc, text ": ", text s])
 
-cbot = panic "CCall:result_ty"
 
 -----------------------------------------------------------------------------
 -- mkVanillaCon
@@ -156,11 +154,11 @@ checkSimple t _ = parseError "Illegal left hand side in data/newtype declaration
 -- checkDo (a) checks that the last thing is an ExprStmt
 --        (b) transforms it to a ResultStmt
 
-checkDo []            = parseError "Empty 'do' construct"
-checkDo [ExprStmt e l] = returnP [ResultStmt e l]
-checkDo [s]           = parseError "The last statement in a 'do' construct must be an expression"
-checkDo (s:ss)        = checkDo ss     `thenP` \ ss' ->
-                        returnP (s:ss')
+checkDo []              = parseError "Empty 'do' construct"
+checkDo [ExprStmt e _ l] = returnP [ResultStmt e l]
+checkDo [s]             = parseError "The last statement in a 'do' construct must be an expression"
+checkDo (s:ss)          = checkDo ss   `thenP` \ ss' ->
+                          returnP (s:ss')
 
 ---------------------------------------------------------------------------
 -- Checking Patterns.
@@ -209,7 +207,7 @@ checkPat e [] = case e of
                                 _ -> patFail
 
        HsPar e            -> checkPat e [] `thenP` (returnP . ParPatIn)
-       ExplicitList es    -> mapP (\e -> checkPat e []) es `thenP` \ps ->
+       ExplicitList _ es  -> mapP (\e -> checkPat e []) es `thenP` \ps ->
                              returnP (ListPatIn ps)
 
        ExplicitTuple es b -> mapP (\e -> checkPat e []) es `thenP` \ps ->
index 99b2864..71b2eb5 100644 (file)
@@ -1,6 +1,6 @@
 {-
 -----------------------------------------------------------------------------
-$Id: Parser.y,v 1.69 2001/06/27 11:15:34 simonmar Exp $
+$Id: Parser.y,v 1.70 2001/07/12 16:21:23 simonpj Exp $
 
 Haskell grammar.
 
@@ -693,9 +693,8 @@ valdef :: { RdrBinding }
 
 
 rhs    :: { RdrNameGRHSs }
-       : '=' srcloc exp wherebinds     { (GRHSs (unguardedRHS $3 $2) 
-                                                               $4 Nothing)}
-       | gdrhs wherebinds              { GRHSs (reverse $1) $2 Nothing }
+       : '=' srcloc exp wherebinds     { (GRHSs (unguardedRHS $3 $2) $4 placeHolderType)}
+       | gdrhs wherebinds              { GRHSs (reverse $1) $2 placeHolderType }
 
 gdrhs :: { [RdrNameGRHS] }
        : gdrhs gdrh                    { $2 : $1 }
@@ -722,7 +721,7 @@ exp10 :: { RdrNameHsExpr }
                        {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps -> 
                           returnP (HsLam (Match [] ps $5 
                                            (GRHSs (unguardedRHS $8 $7) 
-                                                  EmptyBinds Nothing))) }
+                                                  EmptyBinds placeHolderType))) }
        | 'let' declbinds 'in' exp              { HsLet $2 $4 }
        | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
        | 'case' srcloc exp 'of' altslist       { HsCase $3 $5 $2 }
@@ -730,10 +729,10 @@ exp10 :: { RdrNameHsExpr }
        | srcloc 'do' stmtlist                  {% checkDo $3  `thenP` \ stmts ->
                                                   returnP (HsDo DoExpr stmts $1) }
 
-       | '_ccall_'    ccallid aexps0           { HsCCall $2 $3 PlayRisky False cbot }
-       | '_ccall_GC_' ccallid aexps0           { HsCCall $2 $3 PlaySafe  False cbot }
-       | '_casm_'     CLITLIT aexps0           { HsCCall $2 $3 PlayRisky True  cbot }
-       | '_casm_GC_'  CLITLIT aexps0           { HsCCall $2 $3 PlaySafe  True  cbot }
+       | '_ccall_'    ccallid aexps0           { HsCCall $2 $3 PlayRisky False placeHolderType }
+       | '_ccall_GC_' ccallid aexps0           { HsCCall $2 $3 PlaySafe  False placeHolderType }
+       | '_casm_'     CLITLIT aexps0           { HsCCall $2 $3 PlayRisky True  placeHolderType }
+       | '_casm_GC_'  CLITLIT aexps0           { HsCCall $2 $3 PlaySafe  True  placeHolderType }
 
         | scc_annot exp                                { if opt_SccProfilingOn
                                                        then HsSCC $1 $2
@@ -798,8 +797,8 @@ texps :: { [RdrNameHsExpr] }
 -- avoiding another shift/reduce-conflict.
 
 list :: { RdrNameHsExpr }
-       : exp                           { ExplicitList [$1] }
-       | lexps                         { ExplicitList (reverse $1) }
+       : exp                           { ExplicitList placeHolderType [$1] }
+       | lexps                         { ExplicitList placeHolderType (reverse $1) }
        | exp '..'                      { ArithSeqIn (From $1) }
        | exp ',' exp '..'              { ArithSeqIn (FromThen $1 $3) }
        | exp '..' exp                  { ArithSeqIn (FromTo $1 $3) }
@@ -848,7 +847,7 @@ alt         :: { RdrNameMatch }
        : srcloc infixexp opt_sig ralt wherebinds
                                        {% (checkPattern $1 $2 `thenP` \p ->
                                           returnP (Match [] [p] $3
-                                                    (GRHSs $4 $5 Nothing))  )}
+                                                    (GRHSs $4 $5 placeHolderType))  )}
 
 ralt :: { [RdrNameGRHS] }
        : '->' srcloc exp               { [GRHS [ResultStmt $3 $2] $2] }
@@ -891,7 +890,7 @@ maybe_stmt :: { Maybe RdrNameStmt }
 stmt  :: { RdrNameStmt }
        : srcloc infixexp '<-' exp      {% checkPattern $1 $2 `thenP` \p ->
                                           returnP (BindStmt p $4 $1) }
-       | srcloc exp                    { ExprStmt $2 $1 }
+       | srcloc exp                    { ExprStmt $2 placeHolderType $1 }
        | srcloc 'let' declbinds        { LetStmt $3 }
 
 -----------------------------------------------------------------------------
@@ -1095,7 +1094,7 @@ literal :: { HsLit }
        | PRIMSTRING            { HsStringPrim $1 }
        | PRIMFLOAT             { HsFloatPrim  $1 }
        | PRIMDOUBLE            { HsDoublePrim $1 }
-       | CLITLIT               { HsLitLit     $1 (error "Parser.y: CLITLIT") }
+       | CLITLIT               { HsLitLit     $1 placeHolderType }
 
 srcloc :: { SrcLoc }   :       {% getSrcLocP }
  
index e7add89..1f59e86 100644 (file)
@@ -226,11 +226,10 @@ bindPatSigTyVars tys thing_inside
 \begin{code}
 rnGRHSs :: RdrNameGRHSs -> RnMS (RenamedGRHSs, FreeVars)
 
-rnGRHSs (GRHSs grhss binds maybe_ty)
-  = ASSERT( not (maybeToBool maybe_ty) )
-    rnBinds binds              $ \ binds' ->
+rnGRHSs (GRHSs grhss binds _)
+  = rnBinds binds              $ \ binds' ->
     mapFvRn rnGRHS grhss       `thenRn` \ (grhss', fvGRHSs) ->
-    returnRn (GRHSs grhss' binds' Nothing, fvGRHSs)
+    returnRn (GRHSs grhss' binds' placeHolderType, fvGRHSs)
 
 rnGRHS (GRHS guarded locn)
   = doptRn Opt_GlasgowExts             `thenRn` \ opt_GlasgowExts ->
@@ -247,9 +246,9 @@ rnGRHS (GRHS guarded locn)
        -- Standard Haskell 1.4 guards are just a single boolean
        -- expression, rather than a list of qualifiers as in the
        -- Glasgow extension
-    is_standard_guard [ResultStmt _ _]               = True
-    is_standard_guard [ExprStmt _ _, ResultStmt _ _] = True
-    is_standard_guard other                         = False
+    is_standard_guard [ResultStmt _ _]                 = True
+    is_standard_guard [ExprStmt _ _ _, ResultStmt _ _] = True
+    is_standard_guard other                           = False
 \end{code}
 
 %************************************************************************
@@ -355,13 +354,13 @@ rnExpr section@(SectionR op expr)
     checkSectionPrec "right" section op' expr' `thenRn_`
     returnRn (SectionR op' expr', fvs_op `plusFV` fvs_expr)
 
-rnExpr (HsCCall fun args may_gc is_casm fake_result_ty)
+rnExpr (HsCCall fun args may_gc is_casm _)
        -- Check out the comment on RnIfaces.getNonWiredDataDecl about ccalls
   = lookupOrigNames [cCallableClass_RDR, 
                          cReturnableClass_RDR, 
                          ioDataCon_RDR]        `thenRn` \ implicit_fvs ->
     rnExprs args                               `thenRn` \ (args', fvs_args) ->
-    returnRn (HsCCall fun args' may_gc is_casm fake_result_ty, 
+    returnRn (HsCCall fun args' may_gc is_casm placeHolderType, 
              fvs_args `plusFV` implicit_fvs)
 
 rnExpr (HsSCC lbl expr)
@@ -401,9 +400,9 @@ rnExpr e@(HsDo do_or_lc stmts src_loc)
        -- Oh well.
 
 
-rnExpr (ExplicitList exps)
+rnExpr (ExplicitList _ exps)
   = rnExprs exps                       `thenRn` \ (exps', fvs) ->
-    returnRn  (ExplicitList exps', fvs `addOneFV` listTyCon_name)
+    returnRn  (ExplicitList placeHolderType exps', fvs `addOneFV` listTyCon_name)
 
 rnExpr (ExplicitTuple exps boxity)
   = rnExprs exps                               `thenRn` \ (exps', fvs) ->
@@ -596,10 +595,10 @@ rnStmt (BindStmt pat expr src_loc) thing_inside
   where
     doc = text "In a pattern in 'do' binding" 
 
-rnStmt (ExprStmt expr src_loc) thing_inside
+rnStmt (ExprStmt expr _ src_loc) thing_inside
   = pushSrcLocRn src_loc $
-    rnExpr expr                                `thenRn` \ (expr', fv_expr) ->
-    thing_inside (ExprStmt expr' src_loc)      `thenRn` \ (result, fvs) ->
+    rnExpr expr                                                `thenRn` \ (expr', fv_expr) ->
+    thing_inside (ExprStmt expr' placeHolderType src_loc)      `thenRn` \ (result, fvs) ->
     returnRn (result, fv_expr `plusFV` fvs)
 
 rnStmt (ResultStmt expr src_loc) thing_inside
@@ -877,7 +876,7 @@ mkAssertExpr =
      vname = mkSysLocalName uniq SLIT("v")
      expr  = HsLam ignorePredMatch
      loc   = nameSrcLoc vname
-     ignorePredMatch = mkSimpleMatch [WildPatIn, VarPatIn vname] (HsVar vname) Nothing loc
+     ignorePredMatch = mkSimpleMatch [WildPatIn, VarPatIn vname] (HsVar vname) placeHolderType loc
     in
     returnRn (expr, unitFV name)
   else
index d852d48..81e6077 100644 (file)
@@ -14,7 +14,7 @@ import HsSyn          ( TyClDecl(..), Sig(..), MonoBinds(..),
                          HsExpr(..), HsLit(..), HsType(..), HsPred(..), 
                          mkSimpleMatch, andMonoBinds, andMonoBindList, 
                          isClassOpSig, isPragSig,
-                         getClassDeclSysNames, 
+                         getClassDeclSysNames, placeHolderType
                        )
 import BasicTypes      ( TopLevelFlag(..), RecFlag(..) )
 import RnHsSyn         ( RenamedTyClDecl, 
@@ -517,7 +517,7 @@ tcMethodBind clas origin inst_tyvars inst_tys inst_theta
        Just user_bind -> returnTc user_bind 
        Nothing        -> mkDefMethRhs is_inst_decl clas inst_tys sel_id loc dm_info    `thenTc` \ rhs ->
                          returnTc (FunMonoBind meth_name False -- Not infix decl
-                                               [mkSimpleMatch [] rhs Nothing loc] loc)
+                                               [mkSimpleMatch [] rhs placeHolderType loc] loc)
     )                                                          `thenTc` \ meth_bind ->
      -- Check the bindings; first add inst_tyvars to the envt
      -- so that we don't quantify over them in nested places
index 1216001..810ea72 100644 (file)
@@ -359,10 +359,10 @@ tcMonoExpr expr@(HsDo do_or_lc stmts src_loc) res_ty
 \end{code}
 
 \begin{code}
-tcMonoExpr in_expr@(ExplicitList exprs) res_ty -- Non-empty list
+tcMonoExpr in_expr@(ExplicitList _ exprs) res_ty       -- Non-empty list
   = unifyListTy res_ty                        `thenTc` \ elt_ty ->  
     mapAndUnzipTc (tc_elt elt_ty) exprs              `thenTc` \ (exprs', lies) ->
-    returnTc (ExplicitListOut elt_ty exprs', plusLIEs lies)
+    returnTc (ExplicitList elt_ty exprs', plusLIEs lies)
   where
     tc_elt elt_ty expr
       = tcAddErrCtxt (listCtxt expr) $
@@ -536,7 +536,7 @@ tcMonoExpr expr@(RecordUpd record_expr rbinds) res_ty
     newDicts RecordUpdOrigin theta'    `thenNF_Tc` \ dicts ->
 
        -- Phew!
-    returnTc (RecordUpdOut record_expr' result_record_ty (map instToId dicts) rbinds', 
+    returnTc (RecordUpdOut record_expr' record_ty result_record_ty (map instToId dicts) rbinds', 
              mkLIE dicts `plusLIE` record_lie `plusLIE` rbinds_lie)
 
 tcMonoExpr (ArithSeqIn seq@(From expr)) res_ty
@@ -776,7 +776,7 @@ tcDoStmts do_or_lc stmts src_loc res_ty
 
        _       -> newTyVarTy (mkArrowKind liftedTypeKind liftedTypeKind)       `thenNF_Tc` \ m_ty ->
                   newTyVarTy liftedTypeKind                                    `thenNF_Tc` \ elt_ty ->
-                  unifyTauTy res_ty (mkAppTy m_ty elt_ty)                              `thenTc_`
+                  unifyTauTy res_ty (mkAppTy m_ty elt_ty)                      `thenTc_`
                   returnNF_Tc (m_ty, (mkAppTy m_ty, elt_ty))
     )                                                  `thenNF_Tc` \ (tc_ty, m_ty) ->
 
index 2ddc307..0008921 100644 (file)
@@ -29,7 +29,7 @@ module TcGenDeriv (
 import HsSyn           ( InPat(..), HsExpr(..), MonoBinds(..),
                          Match(..), GRHSs(..), Stmt(..), HsLit(..),
                          HsBinds(..), HsType(..), HsDoContext(..),
-                         unguardedRHS, mkSimpleMatch, mkMonoBind, andMonoBindList
+                         unguardedRHS, mkSimpleMatch, mkMonoBind, andMonoBindList, placeHolderType
                        )
 import RdrHsSyn                ( mkHsOpApp, RdrNameMonoBinds, RdrNameHsExpr, RdrNamePat )
 import RdrName         ( RdrName, mkUnqual )
@@ -666,7 +666,7 @@ gen_Ix_binds tycon
           in
           HsCase
             (genOpApp (HsVar dh_RDR) minusH_RDR (HsVar ah_RDR))
-            [mkSimpleMatch [VarPatIn c_RDR] rhs Nothing tycon_loc]
+            [mkSimpleMatch [VarPatIn c_RDR] rhs placeHolderType tycon_loc]
             tycon_loc
           ))
        ) {-else-} (
@@ -1182,7 +1182,7 @@ mk_FunMonoBind loc fun pats_and_exprs
 
 mk_match loc pats expr binds
   = Match [] (map paren pats) Nothing 
-         (GRHSs (unguardedRHS expr loc) binds Nothing)
+         (GRHSs (unguardedRHS expr loc) binds placeHolderType)
   where
     paren p@(VarPatIn _) = p
     paren other_p       = ParPatIn other_p
@@ -1216,9 +1216,9 @@ cmp_eq_Expr a b = HsApp (HsApp (HsVar cmp_eq_RDR) a) b
 
 compare_gen_Case fun lt eq gt a b
   = HsCase (HsPar (HsApp (HsApp (HsVar fun) a) b)) {-of-}
-      [mkSimpleMatch [ConPatIn ltTag_RDR []] lt Nothing generatedSrcLoc,
-       mkSimpleMatch [ConPatIn eqTag_RDR []] eq Nothing generatedSrcLoc,
-       mkSimpleMatch [ConPatIn gtTag_RDR []] gt Nothing generatedSrcLoc]
+      [mkSimpleMatch [ConPatIn ltTag_RDR []] lt placeHolderType generatedSrcLoc,
+       mkSimpleMatch [ConPatIn eqTag_RDR []] eq placeHolderType generatedSrcLoc,
+       mkSimpleMatch [ConPatIn gtTag_RDR []] gt placeHolderType generatedSrcLoc]
       generatedSrcLoc
 
 careful_compare_Case ty lt eq gt a b
@@ -1282,7 +1282,7 @@ untag_Expr :: TyCon -> [(RdrName, RdrName)] -> RdrNameHsExpr -> RdrNameHsExpr
 untag_Expr tycon [] expr = expr
 untag_Expr tycon ((untag_this, put_tag_here) : more) expr
   = HsCase (HsPar (HsApp (con2tag_Expr tycon) (HsVar untag_this))) {-of-}
-      [mkSimpleMatch [VarPatIn put_tag_here] (untag_Expr tycon more expr) Nothing generatedSrcLoc]
+      [mkSimpleMatch [VarPatIn put_tag_here] (untag_Expr tycon more expr) placeHolderType generatedSrcLoc]
       generatedSrcLoc
 
 cmp_tags_Expr :: RdrName               -- Comparison op
index 01266c6..df69c72 100644 (file)
@@ -26,6 +26,8 @@ module TcHsSyn (
        mkHsTyApp, mkHsDictApp, mkHsConApp,
        mkHsTyLam, mkHsDictLam, mkHsLet,
 
+       collectTypedPatBinders, outPatType,
+
        -- re-exported from TcEnv
        TcId, 
 
@@ -44,9 +46,11 @@ import DataCon       ( dataConWrapId )
 import TcEnv   ( tcLookupGlobal_maybe, tcExtendGlobalValEnv, TcEnv, TcId )
 
 import TcMonad
-import TcMType ( zonkTcTypeToType, zonkTcTyVarToTyVar, zonkTcType, zonkTcSigTyVars )
-import CoreSyn  ( Expr )
-import BasicTypes ( RecFlag(..) )
+import Type      ( Type )
+import TcMType   ( zonkTcTypeToType, zonkTcTyVarToTyVar, zonkTcType, zonkTcSigTyVars )
+import TysWiredIn ( mkListTy, mkTupleTy, unitTy )
+import CoreSyn    ( Expr )
+import BasicTypes ( RecFlag(..), Boxity(..) )
 import Bag
 import Outputable
 import HscTypes        ( TyThing(..) )
@@ -117,6 +121,60 @@ mkHsLet mbinds            expr = HsLet (MonoBind mbinds [] Recursive) expr
 mkHsConApp data_con tys args = foldl HsApp (HsVar (dataConWrapId data_con) `mkHsTyApp` tys) args
 \end{code}
 
+
+%************************************************************************
+%*                                                                     *
+\subsection[mkFailurePair]{Code for pattern-matching and other failures}
+%*                                                                     *
+%************************************************************************
+
+Note: If @outPatType@ doesn't bear a strong resemblance to @exprType@,
+then something is wrong.
+\begin{code}
+outPatType :: TypecheckedPat -> Type
+
+outPatType (WildPat ty)                = ty
+outPatType (VarPat var)                = idType var
+outPatType (LazyPat pat)       = outPatType pat
+outPatType (AsPat var pat)     = idType var
+outPatType (ConPat _ ty _ _ _) = ty
+outPatType (ListPat ty _)      = mkListTy ty
+outPatType (TuplePat pats box) = mkTupleTy box (length pats) (map outPatType pats)
+outPatType (RecPat _ ty _ _ _)  = ty
+outPatType (LitPat lit ty)     = ty
+outPatType (NPat lit ty _)     = ty
+outPatType (NPlusKPat _ _ ty _ _) = ty
+outPatType (DictPat ds ms)      = case (length ds_ms) of
+                                   0 -> unitTy
+                                   1 -> idType (head ds_ms)
+                                   n -> mkTupleTy Boxed n (map idType ds_ms)
+                                  where
+                                   ds_ms = ds ++ ms
+\end{code}
+
+
+Nota bene: @DsBinds@ relies on the fact that at least for simple
+tuple patterns @collectTypedPatBinders@ returns the binders in
+the same order as they appear in the tuple.
+
+@collectTypedBinders@ and @collectedTypedPatBinders@ are the exportees.
+
+\begin{code}
+collectTypedPatBinders :: TypecheckedPat -> [Id]
+collectTypedPatBinders (VarPat var)           = [var]
+collectTypedPatBinders (LazyPat pat)          = collectTypedPatBinders pat
+collectTypedPatBinders (AsPat a pat)          = a : collectTypedPatBinders pat
+collectTypedPatBinders (ConPat _ _ _ _ pats)   = concat (map collectTypedPatBinders pats)
+collectTypedPatBinders (ListPat t pats)        = concat (map collectTypedPatBinders pats)
+collectTypedPatBinders (TuplePat pats _)       = concat (map collectTypedPatBinders pats)
+collectTypedPatBinders (RecPat _ _ _ _ fields) = concat (map (\ (f,pat,_) -> collectTypedPatBinders pat)
+                                                         fields)
+collectTypedPatBinders (DictPat ds ms)        = ds ++ ms
+collectTypedPatBinders (NPlusKPat var _ _ _ _) = [var]
+collectTypedPatBinders any_other_pat          = [ {-no binders-} ]
+\end{code}
+
+
 %************************************************************************
 %*                                                                     *
 \subsection[BackSubst-HsBinds]{Running a substitution over @HsBinds@}
@@ -295,7 +353,7 @@ zonkMatch (Match _ pats _ grhss)
 zonkGRHSs :: TcGRHSs
          -> NF_TcM TypecheckedGRHSs
 
-zonkGRHSs (GRHSs grhss binds (Just ty))
+zonkGRHSs (GRHSs grhss binds ty)
   = zonkBinds binds            `thenNF_Tc` \ (new_binds, new_env) ->
     tcSetEnv new_env $
     let
@@ -305,7 +363,7 @@ zonkGRHSs (GRHSs grhss binds (Just ty))
     in
     mapNF_Tc zonk_grhs grhss   `thenNF_Tc` \ new_grhss ->
     zonkTcTypeToType ty        `thenNF_Tc` \ new_ty ->
-    returnNF_Tc (GRHSs new_grhss new_binds (Just new_ty))
+    returnNF_Tc (GRHSs new_grhss new_binds new_ty)
 \end{code}
 
 %************************************************************************
@@ -406,12 +464,10 @@ zonkExpr (HsDoOut do_or_lc stmts return_id then_id zero_id ty src_loc)
     returnNF_Tc (HsDoOut do_or_lc new_stmts new_return_id new_then_id new_zero_id
                         new_ty src_loc)
 
-zonkExpr (ExplicitList _) = panic "zonkExpr:ExplicitList"
-
-zonkExpr (ExplicitListOut ty exprs)
+zonkExpr (ExplicitList ty exprs)
   = zonkTcTypeToType ty                `thenNF_Tc` \ new_ty ->
     mapNF_Tc zonkExpr exprs    `thenNF_Tc` \ new_exprs ->
-    returnNF_Tc (ExplicitListOut new_ty new_exprs)
+    returnNF_Tc (ExplicitList new_ty new_exprs)
 
 zonkExpr (ExplicitTuple exprs boxed)
   = mapNF_Tc zonkExpr exprs    `thenNF_Tc` \ new_exprs ->
@@ -424,12 +480,13 @@ zonkExpr (RecordConOut data_con con_expr rbinds)
 
 zonkExpr (RecordUpd _ _) = panic "zonkExpr:RecordUpd"
 
-zonkExpr (RecordUpdOut expr ty dicts rbinds)
+zonkExpr (RecordUpdOut expr in_ty out_ty dicts rbinds)
   = zonkExpr expr              `thenNF_Tc` \ new_expr ->
-    zonkTcTypeToType ty        `thenNF_Tc` \ new_ty ->
+    zonkTcTypeToType in_ty     `thenNF_Tc` \ new_in_ty ->
+    zonkTcTypeToType out_ty    `thenNF_Tc` \ new_out_ty ->
     mapNF_Tc zonkIdOcc dicts   `thenNF_Tc` \ new_dicts ->
     zonkRbinds rbinds  `thenNF_Tc` \ new_rbinds ->
-    returnNF_Tc (RecordUpdOut new_expr new_ty new_dicts new_rbinds)
+    returnNF_Tc (RecordUpdOut new_expr new_in_ty new_out_ty new_dicts new_rbinds)
 
 zonkExpr (ExprWithTySig _ _) = panic "zonkExpr:ExprWithTySig"
 zonkExpr (ArithSeqIn _)      = panic "zonkExpr:ArithSeqIn"
@@ -516,10 +573,11 @@ zonkStmts (ResultStmt expr locn : stmts)
     zonkStmts stmts    `thenNF_Tc` \ new_stmts ->
     returnNF_Tc (ResultStmt new_expr locn : new_stmts)
 
-zonkStmts (ExprStmt expr locn : stmts)
+zonkStmts (ExprStmt expr ty locn : stmts)
   = zonkExpr expr      `thenNF_Tc` \ new_expr ->
+    zonkTcTypeToType ty        `thenNF_Tc` \ new_ty ->
     zonkStmts stmts    `thenNF_Tc` \ new_stmts ->
-    returnNF_Tc (ExprStmt new_expr locn : new_stmts)
+    returnNF_Tc (ExprStmt new_expr new_ty locn : new_stmts)
 
 zonkStmts (LetStmt binds : stmts)
   = zonkBinds binds            `thenNF_Tc` \ (new_binds, new_env) ->
index 94c406e..2914f61 100644 (file)
@@ -180,7 +180,7 @@ tcGRHSs ctxt (GRHSs grhss binds _) expected_ty
   where
     tc_grhss grhss
        = mapAndUnzipTc tc_grhs grhss       `thenTc` \ (grhss', lies) ->
-         returnTc (GRHSs grhss' EmptyBinds (Just expected_ty), plusLIEs lies)
+         returnTc (GRHSs grhss' EmptyBinds expected_ty, plusLIEs lies)
 
     tc_grhs (GRHS guarded locn)
        = tcAddSrcLoc locn                                      $
@@ -394,19 +394,20 @@ tcStmtAndThen combine do_or_lc m_ty (ParStmtOut bndr_stmts_s) thing_inside
     combine_par stmt (stmts, thing) = (stmt:stmts, thing)
 
        -- ExprStmt
-tcStmtAndThen combine do_or_lc m_ty@(m, res_elt_ty) stmt@(ExprStmt exp locn) thing_inside
+tcStmtAndThen combine do_or_lc m_ty@(m, res_elt_ty) stmt@(ExprStmt exp _ locn) thing_inside
   = tcSetErrCtxt (stmtCtxt do_or_lc stmt) (
        if isDoExpr do_or_lc then
                newTyVarTy openTypeKind         `thenNF_Tc` \ any_ty ->
-               tcExpr exp (m any_ty)   
+               tcExpr exp (m any_ty)           `thenNF_Tc` \ (exp', lie) ->
+               returnTc (ExprStmt exp' any_ty locn, lie)
        else
-               tcExpr exp boolTy
-    )                                          `thenTc` \ (exp', stmt_lie) ->
+               tcExpr exp boolTy               `thenNF_Tc` \ (exp', lie) ->
+               returnTc (ExprStmt exp' boolTy locn, lie)
+    )                                          `thenTc` \ (stmt', stmt_lie) ->
 
     thing_inside                               `thenTc` \ (thing, stmts_lie) ->
 
-    returnTc (combine (ExprStmt exp' locn) thing,
-             stmt_lie `plusLIE` stmts_lie)
+    returnTc (combine stmt' thing, stmt_lie `plusLIE` stmts_lie)
 
 
        -- Result statements
index 3ebbc7e..044118b 100644 (file)
@@ -14,7 +14,7 @@ module TcModule (
 import CmdLineOpts     ( DynFlag(..), DynFlags, dopt )
 import HsSyn           ( HsBinds(..), MonoBinds(..), HsDecl(..), HsExpr(..),
                          Stmt(..), InPat(..), HsMatchContext(..), HsDoContext(..), RuleDecl(..),
-                         isIfaceRuleDecl, nullBinds, andMonoBindList, mkSimpleMatch
+                         isIfaceRuleDecl, nullBinds, andMonoBindList, mkSimpleMatch, placeHolderType
                        )
 import PrelNames       ( SyntaxMap, mAIN_Name, mainName, ioTyConName, printName,
                          returnIOName, bindIOName, failIOName, 
@@ -158,18 +158,18 @@ Here is the grand plan, implemented in tcUserStmt
 \begin{code}
 tcUserStmt :: [Name] -> RenamedStmt -> TcM (TypecheckedHsExpr, [Id])
 
-tcUserStmt names (ExprStmt expr loc)
+tcUserStmt names (ExprStmt expr _ loc)
   = ASSERT( null names )
     tcGetUnique                `thenNF_Tc` \ uniq ->
     let 
        fresh_it = itName uniq
         the_bind = FunMonoBind fresh_it False 
-                       [ mkSimpleMatch [] expr Nothing loc ] loc
+                       [ mkSimpleMatch [] expr placeHolderType loc ] loc
     in
     tryTc_ (traceTc (text "tcs 1b") `thenNF_Tc_`
                tc_stmts [fresh_it] [
                    LetStmt (MonoBind the_bind [] NonRecursive),
-                   ExprStmt (HsApp (HsVar printName) (HsVar fresh_it)) loc])
+                   ExprStmt (HsApp (HsVar printName) (HsVar fresh_it)) placeHolderType loc])
           (    traceTc (text "tcs 1a") `thenNF_Tc_`
                tc_stmts [fresh_it] [BindStmt (VarPatIn fresh_it) expr loc])
 
@@ -189,7 +189,7 @@ tc_stmts names stmts
                -- mk_return builds the expression
                --      returnIO @ [()] [coerce () x, ..,  coerce () z]
        mk_return ids = HsApp (TyApp (HsVar return_id) [mkListTy unitTy]) 
-                             (ExplicitListOut unitTy (map mk_item ids))
+                             (ExplicitList unitTy (map mk_item ids))
 
        mk_item id = HsApp (TyApp (HsVar unsafeCoerceId) [idType id, unitTy])
                           (HsVar id)
index 33a5c6a..19b4ed5 100644 (file)
@@ -347,7 +347,7 @@ OK, so it it legal to give an explicit, user type signature to f, thus:
        f x = (x::Int) + ?y
 
 At first sight this seems reasonable, but it has the nasty property
-that adding a type signature changes the dynamic semantics.=20
+that adding a type signature changes the dynamic semantics.
 Consider this:
 
        (let f x = (x::Int) + ?y
@@ -355,7 +355,7 @@ Consider this:
 
                returns (3+6, 3+5)
 vs
-       (let f :: Int -> Int=20
+       (let f :: Int -> Int
             f x = x + ?y
         in (f 3, f 3 with ?y=5))  with ?y = 6
 
@@ -374,11 +374,11 @@ There's a nasty corner case when the monomorphism restriction bites:
 
        z = (x::Int) + ?y
 
-The argument above suggests that we *must* generalise=20
-over the ?y parameter, to get=20
+The argument above suggests that we *must* generalise
+over the ?y parameter, to get
        z :: (?y::Int) => Int,
 but the monomorphism restriction says that we *must not*, giving
-       z :: Int. =20
+       z :: Int. 
 Why does the momomorphism restriction say this?  Because if you have
 
        let z = x + ?y in z+z
@@ -446,11 +446,11 @@ if we say that we get the value of ?y from the definition site of 'z',
 then inlining 'z' might change the semantics of the program.
 
 Choice (C) really says "the monomorphism restriction doesn't apply
-to implicit parameters".  Which is fine, but remember that every=20
+to implicit parameters".  Which is fine, but remember that every
 innocent binding 'x = ...' that mentions an implicit parameter in
 the RHS becomes a *function* of that parameter, called at each
 use of 'x'.  Now, the chances are that there are no intervening 'with'
-clauses that bind ?y, so a decent compiler should common up all=20
+clauses that bind ?y, so a decent compiler should common up all
 those function calls.  So I think I strongly favour (C).  Indeed,
 one could make a similar argument for abolishing the monomorphism
 restriction altogether.
index 41a5660..1fe3575 100644 (file)
@@ -5,7 +5,7 @@ module Generics ( mkTyConGenInfo, mkGenericRhs,
 
 
 import RnHsSyn         ( RenamedHsExpr )
-import HsSyn           ( HsExpr(..), InPat(..), mkSimpleMatch )
+import HsSyn           ( HsExpr(..), InPat(..), mkSimpleMatch, placeHolderType )
 
 import Type             ( Type, isUnLiftedType, tyVarsOfType, tyVarsOfTypes,
                          mkTyVarTys, mkForAllTys, mkTyConApp, 
@@ -528,7 +528,7 @@ genericNames :: [Name]
 genericNames = [mkSysLocalName (mkBuiltinUnique i) (_PK_ ('g' : show i)) | i <- [1..]]
 (g1:g2:g3:_) = genericNames
 
-mk_hs_lam pats body = HsPar (HsLam (mkSimpleMatch pats body Nothing builtinSrcLoc))
+mk_hs_lam pats body = HsPar (HsLam (mkSimpleMatch pats body placeHolderType builtinSrcLoc))
 
 idEP :: EP RenamedHsExpr
 idEP = EP idexpr idexpr