[project @ 1999-05-26 14:12:07 by simonmar]
[ghc-hetmet.git] / ghc / compiler / types / PprType.lhs
index 7c2260f..8c29300 100644 (file)
@@ -18,7 +18,7 @@ module PprType(
 
 -- friends:
 -- (PprType can see all the representations it's trying to print)
-import Type            ( Type(..), TyNote(..), Kind, ThetaType, 
+import Type            ( Type(..), TyNote(..), Kind, ThetaType, UsageAnn(..),
                          splitDictTy_maybe,
                          splitForAllTys, splitSigmaTy, splitRhoTy,
                          isDictTy, splitTyConApp_maybe, splitFunTy_maybe,
@@ -118,7 +118,7 @@ ppr_ty env ctxt_prec ty@(TyConApp tycon tys)
     case ty1 of
        TyConApp bx [] -> ppr bx
        other          -> maybeParen ctxt_prec tYCON_PREC 
-                                    (ppr tycon <+> tys_w_spaces)
+                                    (sep [ppr tycon, nest 4 tys_w_spaces])
                       
        
        -- TUPLE CASE (boxed and unboxed)
@@ -146,7 +146,7 @@ ppr_ty env ctxt_prec ty@(TyConApp tycon tys)
 
        -- GENERAL CASE
   | otherwise
-  = maybeParen ctxt_prec tYCON_PREC (hsep [ppr tycon, tys_w_spaces])
+  = maybeParen ctxt_prec tYCON_PREC (sep [ppr tycon, nest 4 tys_w_spaces])
 
   where
     tycon_uniq = tyConUnique tycon
@@ -155,7 +155,7 @@ ppr_ty env ctxt_prec ty@(TyConApp tycon tys)
     Just ctys  = maybe_dict
     maybe_dict = splitDictTy_maybe ty  -- Checks class and arity
     tys_w_commas = sep (punctuate comma (map (ppr_ty env tOP_PREC) tys))
-    tys_w_spaces = hsep (map (ppr_ty env tYCON_PREC) tys)
+    tys_w_spaces = sep (map (ppr_ty env tYCON_PREC) tys)
   
 
 
@@ -163,26 +163,30 @@ ppr_ty env ctxt_prec ty@(ForAllTy _ _)
   = getPprStyle $ \ sty -> 
     maybeParen ctxt_prec fUN_PREC $
     if ifaceStyle sty then
-       sep [ ptext SLIT("__forall") <+> brackets pp_tyvars, pp_ctxt, pp_body ]
+       sep [ ptext SLIT("__forall") <+> brackets pp_tyvars <+> ptext SLIT("=>"), 
+            ppr_ty env tOP_PREC rho
+          ]
     else
-       sep [ ptext SLIT("forall") <+> pp_tyvars <> ptext SLIT("."), pp_maybe_ctxt, pp_body ]
+       -- The type checker occasionally prints a type in an error message,
+       -- and it had better come out looking like a user type
+       sep [ ptext SLIT("forall") <+> pp_tyvars <> ptext SLIT("."), 
+            ppr_theta theta <+> ptext SLIT("=>"),
+            ppr_ty env tOP_PREC tau
+          ]
   where                
-    (tyvars, rho_ty) = splitForAllTys ty
-    (theta, body_ty) = splitRhoTy rho_ty
+    (tyvars, rho) = splitForAllTys ty  -- don't treat theta specially any more (KSW 1999-04)
+    (theta, tau)  = splitRhoTy rho
     
     pp_tyvars = hsep (map (pBndr env LambdaBind) tyvars)
-    pp_body   = ppr_ty env tOP_PREC body_ty
     
-    pp_maybe_ctxt | null theta = empty
-                 | otherwise  = pp_ctxt
-
-    pp_ctxt = ppr_theta env theta <+> ptext SLIT("=>") 
+    ppr_theta theta     = parens (hsep (punctuate comma (map ppr_dict theta)))
+    ppr_dict (clas,tys) = ppr clas <+> hsep (map (ppr_ty env tYCON_PREC) tys)
 
 
 ppr_ty env ctxt_prec (FunTy ty1 ty2)
   = maybeParen ctxt_prec fUN_PREC (sep (ppr_ty env fUN_PREC ty1 : pp_rest ty2))
   -- we don't want to lose usage annotations or synonyms,
-  -- so we can't use splitFunTys here.
+  -- so we mustn't use splitFunTys here.
   where
     pp_rest (FunTy ty1 ty2) = pp_codom ty1 : pp_rest ty2
     pp_rest ty              = [pp_codom ty]
@@ -194,9 +198,14 @@ ppr_ty env ctxt_prec (AppTy ty1 ty2)
 
 ppr_ty env ctxt_prec (NoteTy (SynNote ty) expansion)
   = ppr_ty env ctxt_prec ty
+--  = ppr_ty env ctxt_prec expansion -- if we don't want to see syntys
 
 ppr_ty env ctxt_prec (NoteTy (FTVNote _) ty) = ppr_ty env ctxt_prec ty
 
+ppr_ty env ctxt_prec (NoteTy (UsgNote u) ty)
+  = maybeParen ctxt_prec tYCON_PREC $
+    ppr u <+> ppr_ty env tYCON_PREC ty
+
 ppr_theta env []    = empty
 ppr_theta env theta = braces (hsep (punctuate comma (map (ppr_dict env tOP_PREC) theta)))
 
@@ -210,6 +219,13 @@ pprTyEnv = initPprEnv b b (Just ppr) b (Just (\site -> pprTyVarBndr)) b
     b = panic "PprType:init_ppr_env"
 \end{code}
 
+\begin{code}
+instance Outputable UsageAnn where
+  ppr UsOnce     = ptext SLIT("__o")
+  ppr UsMany     = ptext SLIT("__m")
+  ppr (UsVar uv) = ptext SLIT("__uv") <> ppr uv
+\end{code}
+
 %************************************************************************
 %*                                                                     *
 \subsection[TyVar]{@TyVar@}
@@ -255,6 +271,7 @@ getTyDescription ty
       TyConApp tycon _ -> getOccString tycon
       NoteTy (FTVNote _) ty  -> getTyDescription ty
       NoteTy (SynNote ty1) _ -> getTyDescription ty1
+      NoteTy (UsgNote _) ty  -> getTyDescription ty
       ForAllTy _ ty    -> getTyDescription ty
     }
   where