- = maybeParen (ctxt_prec >= pREC_CON)
- (hsep [ppr_mono_ty pREC_FUN fun_ty, ppr_mono_ty pREC_CON arg_ty])
-
-ppr_mono_ty ctxt_prec (HsPredTy pred)
- = maybeParen (ctxt_prec >= pREC_FUN) $
- braces (ppr pred)
-
-ppr_mono_ty ctxt_prec ty@(HsUsgForAllTy _ _)
- =
- sep [ ptext SLIT("__fuall") <+> brackets pp_uvars <+> ptext SLIT("=>"),
- ppr_mono_ty pREC_TOP sigma
- ]
- where
- (uvars,sigma) = split [] ty
- pp_uvars = interppSP uvars
-
- split uvs (HsUsgForAllTy uv ty') = split (uv:uvs) ty'
- split uvs ty' = (reverse uvs,ty')
-
-ppr_mono_ty ctxt_prec (HsUsgTy u ty)
- = maybeParen (ctxt_prec >= pREC_CON) $
- ptext SLIT("__u") <+> pp_ua <+> ppr_mono_ty pREC_CON ty
- where
- pp_ua = case u of
- HsUsOnce -> ptext SLIT("-")
- HsUsMany -> ptext SLIT("!")
- HsUsVar uv -> ppr uv
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{Converting from Type to HsType}
-%* *
-%************************************************************************
-
-@toHsType@ converts from a Type to a HsType, making the latter look as
-user-friendly as possible. Notably, it uses synonyms where possible, and
-expresses overloaded functions using the '=>' context part of a HsForAllTy.
-
-\begin{code}
-toHsTyVar :: TyVar -> HsTyVarBndr RdrName
-toHsTyVar tv = IfaceTyVar (toRdrName tv) (tyVarKind tv)
-
-toHsTyVars tvs = map toHsTyVar tvs
-
-toHsType :: Type -> HsType RdrName
-toHsType ty = toHsType' (unUsgTy ty)
- -- For now we just discard the usage
--- = case splitUsgTy ty of
--- (usg, tau) -> HsUsgTy (toHsUsg usg) (toHsType' tau)
-
-toHsType' :: Type -> HsType RdrName
--- Called after the usage is stripped off
--- This function knows the representation of types
-toHsType' (TyVarTy tv) = HsTyVar (toRdrName tv)
-toHsType' (FunTy arg res) = HsFunTy (toHsType arg) (toHsType res)
-toHsType' (AppTy fun arg) = HsAppTy (toHsType fun) (toHsType arg)
-
-toHsType' (NoteTy (SynNote ty) _) = toHsType ty -- Use synonyms if possible!!
-toHsType' (NoteTy _ ty) = toHsType ty
-
-toHsType' (PredTy p) = HsPredTy (toHsPred p)
-
-toHsType' ty@(TyConApp tc tys) -- Must be saturated because toHsType's arg is of kind *
- | not saturated = generic_case
- | isTupleTyCon tc = HsTupleTy (HsTupCon (toRdrName tc) (tupleTyConBoxity tc)) tys'
- | tc `hasKey` listTyConKey = HsListTy (head tys')
- | otherwise = generic_case
- where
- generic_case = foldl HsAppTy (HsTyVar (toRdrName tc)) tys'
- tys' = map toHsType tys
- saturated = length tys == tyConArity tc
-
-toHsType' ty@(ForAllTy _ _) = case splitSigmaTy ty of
- (tvs, preds, tau) -> HsForAllTy (Just (map toHsTyVar tvs))
- (map toHsPred preds)
- (toHsType tau)
-
-
-toHsPred (Class cls tys) = HsPClass (toRdrName cls) (map toHsType tys)
-toHsPred (IParam n ty) = HsPIParam (toRdrName n) (toHsType ty)
-
-toHsContext :: ClassContext -> HsContext RdrName
-toHsContext cxt = [HsPClass (toRdrName cls) (map toHsType tys) | (cls,tys) <- cxt]
-
-toHsUsg UsOnce = HsUsOnce
-toHsUsg UsMany = HsUsMany
-toHsUsg (UsVar v) = HsUsVar (toRdrName v)
-
-toHsFDs :: [FunDep TyVar] -> [FunDep RdrName]
-toHsFDs fds = [(map toRdrName ns, map toRdrName ms) | (ns,ms) <- fds]
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{Comparison}
-%* *
-%************************************************************************
-
-\begin{code}
-instance Ord a => Eq (HsType a) where
- -- The Ord is needed because we keep a
- -- finite map of variables to variables
- (==) a b = eq_hsType emptyEqHsEnv a b
-
-instance Ord a => Eq (HsPred a) where
- (==) a b = eq_hsPred emptyEqHsEnv a b
-
-eqWithHsTyVars :: Ord name =>
- [HsTyVarBndr name] -> [HsTyVarBndr name]
- -> (EqHsEnv name -> Bool) -> Bool
-eqWithHsTyVars = eq_hsTyVars emptyEqHsEnv
-\end{code}
-
-\begin{code}
-type EqHsEnv n = FiniteMap n n
--- Tracks the mapping from L-variables to R-variables
-
-eq_hsVar :: Ord n => EqHsEnv n -> n -> n -> Bool
-eq_hsVar env n1 n2 = case lookupFM env n1 of
- Just n1 -> n1 == n2
- Nothing -> n1 == n2
-
-extendEqHsEnv env n1 n2
- | n1 == n2 = env
- | otherwise = addToFM env n1 n2
+ = maybeParen ctxt_prec pREC_CON $
+ hsep [ppr_mono_lty pREC_FUN fun_ty, ppr_mono_lty pREC_CON arg_ty]
+
+ppr_mono_ty ctxt_prec (HsOpTy ty1 op ty2)
+ = maybeParen ctxt_prec pREC_OP $
+ ppr_mono_lty pREC_OP ty1 <+> ppr op <+> ppr_mono_lty pREC_OP ty2
+
+ppr_mono_ty ctxt_prec (HsParTy ty)
+ = parens (ppr_mono_lty pREC_TOP ty)
+ -- Put the parens in where the user did
+ -- But we still use the precedence stuff to add parens because
+ -- toHsType doesn't put in any HsParTys, so we may still need them
+
+--------------------------
+ppr_fun_ty ctxt_prec ty1 ty2
+ = let p1 = ppr_mono_lty pREC_FUN ty1
+ p2 = ppr_mono_lty pREC_TOP ty2
+ in
+ maybeParen ctxt_prec pREC_FUN $
+ sep [p1, ptext SLIT("->") <+> p2]