+ HsUsOnce -> ptext SLIT("-")
+ HsUsMany -> ptext SLIT("!")
+ HsUsVar uv -> ppr uv
+-- Generics
+ppr_mono_ty ctxt_prec (HsNumTy n) = integer n
+ppr_mono_ty ctxt_prec (HsOpTy ty1 op ty2) = ppr ty1 <+> ppr op <+> ppr ty2
+\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 Name
+toHsTyVar tv = IfaceTyVar (getName tv) (tyVarKind tv)
+
+toHsTyVars tvs = map toHsTyVar tvs
+
+toHsType :: Type -> HsType Name
+toHsType ty = toHsType' (unUsgTy ty)
+ -- For now we just discard the usage
+
+toHsType' :: Type -> HsType Name
+-- Called after the usage is stripped off
+-- This function knows the representation of types
+toHsType' (TyVarTy tv) = HsTyVar (getName 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 (getName tc) (tupleTyConBoxity tc)) tys'
+ | tc `hasKey` listTyConKey = HsListTy (head tys')
+ | otherwise = generic_case
+ where
+ generic_case = foldl HsAppTy (HsTyVar (getName 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 (getName cls) (map toHsType tys)
+toHsPred (IParam n ty) = HsPIParam (getName n) (toHsType ty)
+
+toHsContext :: ClassContext -> HsContext Name
+toHsContext cxt = [HsPClass (getName cls) (map toHsType tys) | (cls,tys) <- cxt]
+
+toHsFDs :: [FunDep TyVar] -> [FunDep Name]
+toHsFDs fds = [(map getName ns, map getName ms) | (ns,ms) <- fds]