X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FhsSyn%2FHsTypes.lhs;h=55369283c8c989f9496bff0418b30a353ebfdfc5;hp=f1343a39ef9aa5e7621b1eb176a34b8751afedc9;hb=7fc749a43b4b6b85d234fa95d4928648259584f4;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1 diff --git a/compiler/hsSyn/HsTypes.lhs b/compiler/hsSyn/HsTypes.lhs index f1343a3..5536928 100644 --- a/compiler/hsSyn/HsTypes.lhs +++ b/compiler/hsSyn/HsTypes.lhs @@ -1,9 +1,18 @@ % +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -\section[HsTypes]{Abstract syntax: user-defined types} + +HsTypes: Abstract syntax: user-defined types \begin{code} +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module HsTypes ( HsType(..), LHsType, HsTyVarBndr(..), LHsTyVarBndr, @@ -14,7 +23,7 @@ module HsTypes ( LBangType, BangType, HsBang(..), getBangType, getBangStrictness, - mkExplicitHsForAllTy, mkImplicitHsForAllTy, + mkExplicitHsForAllTy, mkImplicitHsForAllTy, hsExplicitTvs, hsTyVarName, hsTyVarNames, replaceTyVarName, hsLTyVarName, hsLTyVarNames, hsLTyVarLocName, hsLTyVarLocNames, splitHsInstDeclTy, splitHsFunType, @@ -30,12 +39,11 @@ module HsTypes ( import {-# SOURCE #-} HsExpr ( HsSplice, pprSplice ) -import Type ( Type ) -import Kind ( {- instance Outputable Kind -}, Kind, - pprParendKind, pprKind, isLiftedTypeKind ) -import BasicTypes ( IPName, Boxity, tupleParens ) -import SrcLoc ( Located(..), unLoc, noSrcSpan ) -import StaticFlags ( opt_PprStyle_Debug ) +import Type +import HsDoc +import BasicTypes +import SrcLoc +import StaticFlags import Outputable \end{code} @@ -101,7 +109,8 @@ type HsContext name = [LHsPred name] type LHsPred name = Located (HsPred name) -data HsPred name = HsClassP name [LHsType name] +data HsPred name = HsClassP name [LHsType name] -- class constraint + | HsEqualP (LHsType name) (LHsType name)-- equality constraint | HsIParam (IPName name) (LHsType name) type LHsType name = Located (HsType name) @@ -156,6 +165,8 @@ data HsType name | HsSpliceTy (HsSplice name) + | HsDocTy (LHsType name) (LHsDoc name) -- A documented type + data HsExplicitForAll = Explicit | Implicit ----------------------- @@ -189,6 +200,12 @@ mk_forall_ty exp tvs ty = HsForAllTy exp tvs (L noSrcSpan []) ty Implicit `plus` Implicit = Implicit exp1 `plus` exp2 = Explicit +hsExplicitTvs :: LHsType name -> [name] +-- The explicitly-given forall'd type variables of a HsType +hsExplicitTvs (L _ (HsForAllTy Explicit tvs _ _)) = hsLTyVarNames tvs +hsExplicitTvs other = [] + +--------------------- type LHsTyVarBndr name = Located (HsTyVarBndr name) data HsTyVarBndr name @@ -239,6 +256,7 @@ splitHsInstDeclTy inst_ty where split_tau tvs cxt (HsPredTy (HsClassP cls tys)) = (tvs, cxt, cls, tys) split_tau tvs cxt (HsParTy (L _ ty)) = split_tau tvs cxt ty + split_tau _ _ other = pprPanic "splitHsInstDeclTy" (ppr inst_ty) -- Splits HsType into the (init, last) parts -- Breaks up any parens in the result type: @@ -258,9 +276,6 @@ splitHsFunType other = ([], other) %* * %************************************************************************ -NB: these types get printed into interface files, so - don't change the printing format lightly - \begin{code} instance (OutputableBndr name) => Outputable (HsType name) where ppr ty = pprHsType ty @@ -270,8 +285,13 @@ instance (Outputable name) => Outputable (HsTyVarBndr name) where ppr (KindedTyVar name kind) = pprHsTyVarBndr name kind instance OutputableBndr name => Outputable (HsPred name) where - ppr (HsClassP clas tys) = ppr clas <+> hsep (map (pprParendHsType.unLoc) tys) - ppr (HsIParam n ty) = hsep [ppr n, dcolon, ppr ty] + ppr (HsClassP clas tys) = ppr clas <+> hsep (map pprLHsType tys) + ppr (HsEqualP t1 t2) = hsep [pprLHsType t1, ptext SLIT("~"), + pprLHsType t2] + ppr (HsIParam n ty) = hsep [ppr n, dcolon, ppr ty] + +pprLHsType :: OutputableBndr name => LHsType name -> SDoc +pprLHsType = pprParendHsType . unLoc pprHsTyVarBndr :: Outputable name => name -> Kind -> SDoc pprHsTyVarBndr name kind | isLiftedTypeKind kind = ppr name @@ -329,7 +349,6 @@ ppr_mono_ty ctxt_prec (HsForAllTy exp tvs ctxt ty) = maybeParen ctxt_prec pREC_FUN $ sep [pprHsForAll exp tvs ctxt, ppr_mono_lty pREC_TOP ty] --- gaw 2004 ppr_mono_ty ctxt_prec (HsBangTy b ty) = ppr b <> ppr ty ppr_mono_ty ctxt_prec (HsTyVar name) = ppr name ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2) = ppr_fun_ty ctxt_prec ty1 ty2 @@ -337,7 +356,7 @@ ppr_mono_ty ctxt_prec (HsTupleTy con tys) = tupleParens con (interpp'SP tys) ppr_mono_ty ctxt_prec (HsKindSig ty kind) = parens (ppr_mono_lty pREC_TOP ty <+> dcolon <+> pprKind kind) ppr_mono_ty ctxt_prec (HsListTy ty) = brackets (ppr_mono_lty pREC_TOP ty) ppr_mono_ty ctxt_prec (HsPArrTy ty) = pabrackets (ppr_mono_lty pREC_TOP ty) -ppr_mono_ty ctxt_prec (HsPredTy pred) = braces (ppr pred) +ppr_mono_ty ctxt_prec (HsPredTy pred) = ppr pred ppr_mono_ty ctxt_prec (HsNumTy n) = integer n -- generics only ppr_mono_ty ctxt_prec (HsSpliceTy s) = pprSplice s @@ -355,6 +374,9 @@ ppr_mono_ty ctxt_prec (HsParTy ty) -- 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_mono_ty ctxt_prec (HsDocTy ty doc) + = ppr ty <+> ppr (unLoc doc) + -------------------------- ppr_fun_ty ctxt_prec ty1 ty2 = let p1 = ppr_mono_lty pREC_FUN ty1