PrintAs.hs revision e8ffec0fa3d3061061bdc16e44247b9cf96b050f
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett Authors: Christian Maeder
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett printing As data types
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport Common.GlobalAnnotations(GlobalAnnos)
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblettimport Common.GlobalAnnotationsFunctions(emptyGlobalAnnos)
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedernoPrint :: Bool -> Doc -> Doc
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedernoPrint b d = if b then empty else d
04ceed96d1528b939f2e592d0656290d81d1c045Andy GimblettshowPretty :: PrettyPrint a => a -> ShowS
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettshowPretty = showString . render . printText0 emptyGlobalAnnos
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett where _just_avoid_unused_import_warning = smallSpace_latex
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettcommas, semis :: PrettyPrint a => GlobalAnnos -> [a] -> Doc
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettcommas ga l = fcat $ punctuate comma (map (printText0 ga) l)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettsemis ga l = sep $ punctuate semi (map (printText0 ga) l)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettinstance PrettyPrint TypePattern where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett printText0 ga (TypePattern name args _) = printText0 ga name
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett <> fcat (map (parens . printText0 ga) args)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett printText0 ga (TypePatternToken t) = printText0 ga t
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett printText0 ga (MixfixTypePattern ts) = fsep (map (printText0 ga) ts)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett printText0 ga (BracketTypePattern k l _) = bracket k $ commas ga l
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett printText0 ga (TypePatternArgs l) = semis ga l
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettbracket :: BracketKind -> Doc -> Doc
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettbracket Parens t = parens t
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettbracket Squares t = brackets t
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettbracket Braces t = braces t
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettprintKind :: GlobalAnnos -> Kind -> Doc
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettprintKind ga kind = case kind of
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett PlainClass (Intersection [] _) -> empty
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett _ -> space <> colon <> printText0 ga kind
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblettinstance PrettyPrint Type where
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett printText0 ga (TypeName name i) = printText0 ga name
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett <> if i == 0 then empty
2f06b54890375b6cac90394b80b07bd451d728fcAndy Gimblett else parens (int i)
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett printText0 ga (TypeAppl t1 t2) = parens (printText0 ga t1)
ac5ec613b786cd05f495b568ab5214c31a333e67Andy Gimblett <> parens (printText0 ga t2)
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett printText0 ga (TypeToken t) = printText0 ga t
fcd11c35e645b0744a308f7961a519826bbaa2f5Christian Maeder printText0 ga (BracketType k l _) = bracket k $ commas ga l
fcd11c35e645b0744a308f7961a519826bbaa2f5Christian Maeder printText0 ga (KindedType t kind _) = printText0 ga t
fcd11c35e645b0744a308f7961a519826bbaa2f5Christian Maeder <> space <> colon <> printText0 ga kind
a88d32442096d4fd88fce34842ca6f8cf34d8160Christian Maeder printText0 ga (MixfixType ts) = fsep (map (printText0 ga) ts)
a88d32442096d4fd88fce34842ca6f8cf34d8160Christian Maeder printText0 ga (LazyType t _) = text quMark <+> printText0 ga (t)
a88d32442096d4fd88fce34842ca6f8cf34d8160Christian Maeder printText0 ga (ProductType ts _) = fsep (punctuate (space <> text timesS)
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder (map (printText0 ga) ts))
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder printText0 ga (FunType t1 arr t2 _) = printText0 ga t1
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder <+> printText0 ga arr
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder <+> printText0 ga t2
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maederinstance PrettyPrint Pred where
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder printText0 ga (IsIn c ts) = if null ts then printText0 ga c
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder else if null $ tail ts then
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder printText0 ga (head ts) <+>
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder colon <+> printText0 ga c
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder else printText0 ga c <+>
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder fsep (punctuate space
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder (map (printText0 ga) ts))
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maederinstance PrettyPrint t => PrettyPrint (Qual t) where
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder printText0 ga (ps :=> t) = (if null ps then empty
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder else parens $ commas ga ps <+>
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder ptext implS <+> space) <>
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder printText0 ga t
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder-- no curried notation for bound variables
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maederinstance PrettyPrint TypeScheme where
7bf56dc23f635a1f3cd09e89649a1e7897a77c68Christian Maeder printText0 ga (TypeScheme vss t _) = hcat (map (\ (TypeArgs vs _) ->
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder <+> semis ga vs
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder <+> text dotS <+> space)
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder <> printText0 ga t
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maederinstance PrettyPrint Partiality where
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder printText0 _ Partial = text quMark
(parens.printText0 ga) ps)
<+> fcat (map (parens.printText0 ga) args)