[project @ 1999-04-20 12:59:51 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcType.lhs
index 651c76e..ff0a61e 100644 (file)
@@ -26,6 +26,7 @@ module TcType (
   tcSplitRhoTy,
 
   tcInstTyVars,
+  tcInstSigVar,
   tcInstTcType,
 
   typeToTcType,
@@ -172,16 +173,15 @@ tcInstTyVars :: [TyVar]
             -> NF_TcM s ([TcTyVar], [TcType], TyVarEnv TcType)
 
 tcInstTyVars tyvars
-  = mapNF_Tc inst_tyvar tyvars `thenNF_Tc` \ tc_tyvars ->
+  = mapNF_Tc tcInstTyVar tyvars        `thenNF_Tc` \ tc_tyvars ->
     let
        tys = mkTyVarTys tc_tyvars
     in
     returnNF_Tc (tc_tyvars, tys, zipVarEnv tyvars tys)
 
-inst_tyvar tyvar       -- Could use the name from the tyvar?
+tcInstTyVar tyvar
   = tcGetUnique                `thenNF_Tc` \ uniq ->
     let
-       kind = tyVarKind tyvar
        name = setNameUnique (tyVarName tyvar) uniq
        -- Note that we don't change the print-name
        -- This won't confuse the type checker but there's a chance
@@ -189,8 +189,35 @@ inst_tyvar tyvar   -- Could use the name from the tyvar?
        -- in an error message.  -dppr-debug will show up the difference
        -- Better watch out for this.  If worst comes to worst, just
        -- use mkSysLocalName.
+
+       kind = tyVarKind tyvar
+    in
+
+       -- Hack alert!  Certain system functions (like error) are quantified
+       -- over type variables with an 'open' kind (a :: ?).  When we instantiate
+       -- these tyvars we want to make a type variable whose kind is (Type bv)
+       -- where bv is a boxity variable.  This makes sure it's a type, but 
+       -- is open about its boxity.  We *don't* want to give the thing the
+       -- kind '?' (= Type AnyBox).  
+       --
+       -- This is all a hack to avoid giving error it's "proper" type:
+       --       error :: forall bv. forall a::Type bv. String -> a
+
+    (if kind == openTypeKind then
+       newOpenTypeKind 
+     else
+       returnNF_Tc kind)       `thenNF_Tc` \ kind' ->
+
+    tcNewMutTyVar name kind'
+
+tcInstSigVar tyvar     -- Very similar to tcInstTyVar
+  = tcGetUnique        `thenNF_Tc` \ uniq ->
+    let 
+       name = setNameUnique (tyVarName tyvar) uniq
+       kind = tyVarKind tyvar
     in
-    tcNewMutTyVar name kind
+    ASSERT( not (kind == openTypeKind) )       -- Shouldn't happen
+    tcNewSigTyVar name kind
 \end{code}
 
 @tcInstTcType@ instantiates the outer-level for-alls of a TcType with