[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcMonoType.lhs
index 1825cdf..d933c2f 100644 (file)
@@ -8,15 +8,15 @@
 
 module TcMonoType ( tcPolyType, tcMonoType, tcMonoTypeKind, tcContext ) where
 
-import Ubiq{-uitous-}
+IMP_Ubiq(){-uitous-}
 
 import HsSyn           ( PolyType(..), MonoType(..), Fake )
 import RnHsSyn         ( RenamedPolyType(..), RenamedMonoType(..), 
-                         RenamedContext(..)
+                         RenamedContext(..), RnName(..),
+                         isRnLocal, isRnClass, isRnTyCon
                        )
 
-
-import TcMonad
+import TcMonad         hiding ( rnMtoTcM )
 import TcEnv           ( tcLookupTyVar, tcLookupClass, tcLookupTyCon, 
                          tcTyVarScope, tcTyVarScopeGivenKinds
                        )
@@ -24,20 +24,18 @@ import TcKind               ( TcKind, mkTcTypeKind, mkBoxedTypeKind,
                          mkTcArrowKind, unifyKind, newKindVar,
                          kindToTcKind
                        )
-import Type            ( GenType, Type(..), ThetaType(..), 
+import Type            ( GenType, SYN_IE(Type), SYN_IE(ThetaType), 
                          mkTyVarTy, mkTyConTy, mkFunTy, mkAppTy, mkSynTy,
-                         mkSigmaTy
+                         mkSigmaTy, mkDictTy
                        )
-import TyVar           ( GenTyVar, TyVar(..), mkTyVar )
-import PrelInfo                ( mkListTy, mkTupleTy )
-import Type            ( mkDictTy )
+import TyVar           ( GenTyVar, SYN_IE(TyVar) )
 import Class           ( cCallishClassKeys )
-import TyCon           ( TyCon, Arity(..) )
+import TyCon           ( TyCon )
+import TysWiredIn      ( mkListTy, mkTupleTy )
 import Unique          ( Unique )
-import Name            ( Name(..), getNameShortName, isTyConName, getSynNameArity )
 import PprStyle
 import Pretty
-import Util            ( zipWithEqual, panic )
+import Util            ( zipWithEqual, panic{-, pprPanic ToDo:rm-} )
 \end{code}
 
 
@@ -78,17 +76,19 @@ tcMonoTypeKind (MonoFunTy ty1 ty2)
     tcMonoType ty2     `thenTc` \ tau_ty2 ->
     returnTc (mkTcTypeKind, mkFunTy tau_ty1 tau_ty2)
 
-tcMonoTypeKind (MonoTyApp name@(Short _ _) tys)
-  =    -- Must be a type variable
-    tcLookupTyVar name                 `thenNF_Tc` \ (kind,tyvar) ->
+tcMonoTypeKind (MonoTyApp name tys)
+  | isRnLocal name     -- Must be a type variable
+  = tcLookupTyVar name                 `thenNF_Tc` \ (kind,tyvar) ->
     tcMonoTyApp kind (mkTyVarTy tyvar) tys
 
-tcMonoTypeKind (MonoTyApp name tys)
-  | isTyConName name   -- Must be a type constructor
+  | otherwise {-isRnTyCon name-}       -- Must be a type constructor
   = tcLookupTyCon name                 `thenNF_Tc` \ (kind,maybe_arity,tycon) ->
     case maybe_arity of
        Just arity -> tcSynApp name kind arity tycon tys        -- synonum
        Nothing    -> tcMonoTyApp kind (mkTyConTy tycon) tys    -- newtype or data
+
+--  | otherwise
+--  = pprPanic "tcMonoTypeKind:" (ppr PprDebug name)
        
 -- for unfoldings only:
 tcMonoTypeKind (MonoForAllTy tyvars_w_kinds ty)
@@ -98,8 +98,10 @@ tcMonoTypeKind (MonoForAllTy tyvars_w_kinds ty)
        returnTc (mkTcTypeKind, ty')
     )
   where
-    (names, kinds) = unzip tyvars_w_kinds
+    (rn_names, kinds) = unzip tyvars_w_kinds
+    names    = map de_rn rn_names
     tc_kinds = map kindToTcKind kinds
+    de_rn (RnName n) = n
 
 -- for unfoldings only:
 tcMonoTypeKind (MonoDictTy class_name ty)
@@ -151,32 +153,34 @@ tcClassAssertion (class_name, tyvar_name)
     returnTc (clas, mkTyVarTy tyvar)
 \end{code}
 
-HACK warning: Someone discovered that @_CCallable@ and @_CReturnable@
+HACK warning: Someone discovered that @CCallable@ and @CReturnable@
 could be used in contexts such as:
 \begin{verbatim}
-foo :: _CCallable a => a -> PrimIO Int
+foo :: CCallable a => a -> PrimIO Int
 \end{verbatim}
 
 Doing this utterly wrecks the whole point of introducing these
 classes so we specifically check that this isn't being done.
 
 \begin{code}
-canBeUsedInContext :: Name -> Bool
-canBeUsedInContext (ClassName uniq _ _) = not (uniq `elem` cCallishClassKeys)
-canBeUsedInContext other               = True
+canBeUsedInContext :: RnName -> Bool
+canBeUsedInContext n
+  = isRnClass n && not (uniqueOf n `elem` cCallishClassKeys)
 \end{code}
 
-
 Polytypes
 ~~~~~~~~~
 \begin{code}
 tcPolyType :: RenamedPolyType -> TcM s Type
 tcPolyType (HsForAllTy tyvar_names context ty)
-  = tcTyVarScope tyvar_names (\ tyvars ->
+  = tcTyVarScope names (\ tyvars ->
        tcContext context       `thenTc` \ theta ->
        tcMonoType ty           `thenTc` \ tau ->
        returnTc (mkSigmaTy tyvars theta tau)
     )
+  where
+    names = map de_rn tyvar_names
+    de_rn (RnName n) = n
 \end{code}
 
 Errors and contexts