PrintAs.hs revision da245da15da78363c896e44ea97a14ab1f83eb50
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach Authors: Christian Maeder
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill Mossakowski printing As data types
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachimport qualified Common.Lib.Set as Set
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederimport Common.GlobalAnnotations(GlobalAnnos)
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblettcommas, semis :: PrettyPrint a => GlobalAnnos -> [a] -> Doc
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblettcommas = commaT printText0
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblettsemis = semiT printText0
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblettinstance PrettyPrint TypePattern where
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (TypePattern name args _) = printText0 ga name
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett <> fcat (map (parens . printText0 ga) args)
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga (TypePatternToken t) = printText0 ga t
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga (MixfixTypePattern ts) = fsep (map (printText0 ga) ts)
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga (BracketTypePattern k l _) = bracket k $ commas ga l
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga (TypePatternArg t _) = parens $ printText0 ga t
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblettbracket :: BracketKind -> Doc -> Doc
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblettbracket Parens t = parens t
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblettbracket Squares t = brackets t
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblettbracket Braces t = braces t
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy GimblettprintKind :: GlobalAnnos -> Kind -> Doc
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachprintKind ga kind = case kind of
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett ExtClass (Intersection s _) InVar _ ->
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett if Set.isEmpty s then empty else erg
929190acb9f2b2f5857dce841c5a389710895515Andy Gimblett where erg = space <> colon <> printText0 ga kind
929190acb9f2b2f5857dce841c5a389710895515Andy Gimblettinstance PrettyPrint Type where
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga (TypeName name _k _i) = printText0 ga name
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett-- <> printKind ga k
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett-- <> if i == 0 then empty
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett-- else parens (int i)
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (TypeAppl t1 t2) = parens (printText0 ga t1)
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett <> parens (printText0 ga t2)
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (TypeToken t) = printText0 ga t
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (BracketType k l _) = bracket k $ commas ga l
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (KindedType t kind _) = printText0 ga t
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett <> space <> colon <> printText0 ga kind
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (MixfixType ts) = fsep (map (printText0 ga) ts)
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (LazyType t _) = text quMark <+> printText0 ga (t)
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (ProductType ts _) = fsep (punctuate (space <> text timesS)
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett (map (printText0 ga) ts))
e99df192a380bfa91e3261c911751bb034c09a17Till Mossakowski printText0 ga (FunType t1 arr t2 _) = printText0 ga t1
e99df192a380bfa91e3261c911751bb034c09a17Till Mossakowski <+> printText0 ga arr
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett <+> printText0 ga t2
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblettinstance PrettyPrint Pred where
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (IsIn c ts) = if null ts then printText0 ga c
eca4db63ed0bdbd93b62678feea6e3eb80aa47bbChristian Maeder else if null $ tail ts then
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski printText0 ga (head ts) <+>
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett colon <+> printText0 ga c
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett else printText0 ga c <+>
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski fsep (punctuate space
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski (map (printText0 ga) ts))
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblettinstance PrettyPrint t => PrettyPrint (Qual t) where
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 ga (ps :=> t) = (if null ps then empty
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett else parens $ commas ga ps <+>
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder ptext implS <+> space) <>
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga t
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder-- no curried notation for bound variables
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowskiinstance PrettyPrint TypeScheme where
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett printText0 ga (TypeScheme vs t _) = noPrint (null vs) (text forallS
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski <+> semis ga vs
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder <+> text dotS <+> space)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder <> printText0 ga t
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblettinstance PrettyPrint Partiality where
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 _ Partial = text quMark
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski printText0 _ Total = text exMark
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblettinstance PrettyPrint Arrow where
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 _ FunArr = text funS
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 _ PFunArr = text pFun
afd6ed16928bbd774b6c6c5b3f440a917dd638a1Andy Gimblett printText0 _ ContFunArr = text contFun
(parens.printText0 ga) ps)
<+> fcat (map (parens.printText0 ga) args)
printText0 ga (Intersection c _) = if Set.isEmpty c then ptext "Type"
else printList0 ga $ Set.toList c