some more typos
[ghc.git] / libraries / template-haskell / Language / Haskell / TH / Ppr.hs
1 -- | contains a prettyprinter for the
2 -- Template Haskell datatypes
3
4 module Language.Haskell.TH.Ppr where
5 -- All of the exports from this module should
6 -- be "public" functions. The main module TH
7 -- re-exports them all.
8
9 import Text.PrettyPrint (render)
10 import Language.Haskell.TH.PprLib
11 import Language.Haskell.TH.Syntax
12 import Data.Word ( Word8 )
13 import Data.Char ( toLower, chr )
14 import GHC.Show ( showMultiLineString )
15
16 nestDepth :: Int
17 nestDepth = 4
18
19 type Precedence = Int
20 appPrec, unopPrec, opPrec, noPrec :: Precedence
21 appPrec = 3 -- Argument of a function application
22 opPrec = 2 -- Argument of an infix operator
23 unopPrec = 1 -- Argument of an unresolved infix operator
24 noPrec = 0 -- Others
25
26 parensIf :: Bool -> Doc -> Doc
27 parensIf True d = parens d
28 parensIf False d = d
29
30 ------------------------------
31
32 pprint :: Ppr a => a -> String
33 pprint x = render $ to_HPJ_Doc $ ppr x
34
35 class Ppr a where
36 ppr :: a -> Doc
37 ppr_list :: [a] -> Doc
38 ppr_list = vcat . map ppr
39
40 instance Ppr a => Ppr [a] where
41 ppr x = ppr_list x
42
43 ------------------------------
44 instance Ppr Name where
45 ppr v = pprName v
46
47 ------------------------------
48 instance Ppr Info where
49 ppr (TyConI d) = ppr d
50 ppr (ClassI d is) = ppr d $$ vcat (map ppr is)
51 ppr (FamilyI d is) = ppr d $$ vcat (map ppr is)
52 ppr (PrimTyConI name arity is_unlifted)
53 = text "Primitive"
54 <+> (if is_unlifted then text "unlifted" else empty)
55 <+> text "type constructor" <+> quotes (ppr name)
56 <+> parens (text "arity" <+> int arity)
57 ppr (ClassOpI v ty cls fix)
58 = text "Class op from" <+> ppr cls <> colon <+>
59 vcat [ppr_sig v ty, pprFixity v fix]
60 ppr (DataConI v ty tc fix)
61 = text "Constructor from" <+> ppr tc <> colon <+>
62 vcat [ppr_sig v ty, pprFixity v fix]
63 ppr (TyVarI v ty)
64 = text "Type variable" <+> ppr v <+> equals <+> ppr ty
65 ppr (VarI v ty mb_d fix)
66 = vcat [ppr_sig v ty, pprFixity v fix,
67 case mb_d of { Nothing -> empty; Just d -> ppr d }]
68
69 ppr_sig :: Name -> Type -> Doc
70 ppr_sig v ty = ppr v <+> text "::" <+> ppr ty
71
72 pprFixity :: Name -> Fixity -> Doc
73 pprFixity _ f | f == defaultFixity = empty
74 pprFixity v (Fixity i d) = ppr_fix d <+> int i <+> ppr v
75 where ppr_fix InfixR = text "infixr"
76 ppr_fix InfixL = text "infixl"
77 ppr_fix InfixN = text "infix"
78
79
80 ------------------------------
81 instance Ppr Exp where
82 ppr = pprExp noPrec
83
84 pprInfixExp :: Exp -> Doc
85 pprInfixExp (VarE v) = pprName' Infix v
86 pprInfixExp (ConE v) = pprName' Infix v
87 pprInfixExp _ = text "<<Non-variable/constructor in infix context>>"
88
89 pprExp :: Precedence -> Exp -> Doc
90 pprExp _ (VarE v) = pprName' Applied v
91 pprExp _ (ConE c) = pprName' Applied c
92 pprExp i (LitE l) = pprLit i l
93 pprExp i (AppE e1 e2) = parensIf (i >= appPrec) $ pprExp opPrec e1
94 <+> pprExp appPrec e2
95 pprExp _ (ParensE e) = parens (pprExp noPrec e)
96 pprExp i (UInfixE e1 op e2)
97 = parensIf (i > unopPrec) $ pprExp unopPrec e1
98 <+> pprInfixExp op
99 <+> pprExp unopPrec e2
100 pprExp i (InfixE (Just e1) op (Just e2))
101 = parensIf (i >= opPrec) $ pprExp opPrec e1
102 <+> pprInfixExp op
103 <+> pprExp opPrec e2
104 pprExp _ (InfixE me1 op me2) = parens $ pprMaybeExp noPrec me1
105 <+> pprInfixExp op
106 <+> pprMaybeExp noPrec me2
107 pprExp i (LamE ps e) = parensIf (i > noPrec) $ char '\\' <> hsep (map (pprPat appPrec) ps)
108 <+> text "->" <+> ppr e
109 pprExp i (LamCaseE ms) = parensIf (i > noPrec)
110 $ text "\\case" $$ nest nestDepth (ppr ms)
111 pprExp _ (TupE es) = parens $ sep $ punctuate comma $ map ppr es
112 pprExp _ (UnboxedTupE es) = hashParens $ sep $ punctuate comma $ map ppr es
113 -- Nesting in Cond is to avoid potential problems in do statments
114 pprExp i (CondE guard true false)
115 = parensIf (i > noPrec) $ sep [text "if" <+> ppr guard,
116 nest 1 $ text "then" <+> ppr true,
117 nest 1 $ text "else" <+> ppr false]
118 pprExp i (MultiIfE alts)
119 = parensIf (i > noPrec) $ vcat $
120 case alts of
121 [] -> [text "if {}"]
122 (alt : alts') -> text "if" <+> pprGuarded arrow alt
123 : map (nest 3 . pprGuarded arrow) alts'
124 pprExp i (LetE ds e) = parensIf (i > noPrec) $ text "let" <+> ppr ds
125 $$ text " in" <+> ppr e
126 pprExp i (CaseE e ms)
127 = parensIf (i > noPrec) $ text "case" <+> ppr e <+> text "of"
128 $$ nest nestDepth (ppr ms)
129 pprExp i (DoE ss) = parensIf (i > noPrec) $ text "do" <+> ppr ss
130 pprExp _ (CompE []) = text "<<Empty CompExp>>"
131 -- This will probably break with fixity declarations - would need a ';'
132 pprExp _ (CompE ss) = text "[" <> ppr s
133 <+> text "|"
134 <+> (sep $ punctuate comma $ map ppr ss')
135 <> text "]"
136 where s = last ss
137 ss' = init ss
138 pprExp _ (ArithSeqE d) = ppr d
139 pprExp _ (ListE es) = brackets $ sep $ punctuate comma $ map ppr es
140 pprExp i (SigE e t) = parensIf (i > noPrec) $ ppr e <+> text "::" <+> ppr t
141 pprExp _ (RecConE nm fs) = ppr nm <> braces (pprFields fs)
142 pprExp _ (RecUpdE e fs) = pprExp appPrec e <> braces (pprFields fs)
143
144 pprFields :: [(Name,Exp)] -> Doc
145 pprFields = sep . punctuate comma . map (\(s,e) -> ppr s <+> equals <+> ppr e)
146
147 pprMaybeExp :: Precedence -> Maybe Exp -> Doc
148 pprMaybeExp _ Nothing = empty
149 pprMaybeExp i (Just e) = pprExp i e
150
151 ------------------------------
152 instance Ppr Stmt where
153 ppr (BindS p e) = ppr p <+> text "<-" <+> ppr e
154 ppr (LetS ds) = text "let" <+> ppr ds
155 ppr (NoBindS e) = ppr e
156 ppr (ParS sss) = sep $ punctuate (text "|")
157 $ map (sep . punctuate comma . map ppr) sss
158
159 ------------------------------
160 instance Ppr Match where
161 ppr (Match p rhs ds) = ppr p <+> pprBody False rhs
162 $$ where_clause ds
163
164 ------------------------------
165 pprGuarded :: Doc -> (Guard, Exp) -> Doc
166 pprGuarded eqDoc (guard, expr) = case guard of
167 NormalG guardExpr -> char '|' <+> ppr guardExpr <+> eqDoc <+> ppr expr
168 PatG stmts -> char '|' <+> vcat (punctuate comma $ map ppr stmts) $$
169 nest nestDepth (eqDoc <+> ppr expr)
170
171 ------------------------------
172 pprBody :: Bool -> Body -> Doc
173 pprBody eq body = case body of
174 GuardedB xs -> nest nestDepth $ vcat $ map (pprGuarded eqDoc) xs
175 NormalB e -> eqDoc <+> ppr e
176 where eqDoc | eq = equals
177 | otherwise = arrow
178
179 ------------------------------
180 pprLit :: Precedence -> Lit -> Doc
181 pprLit i (IntPrimL x) = parensIf (i > noPrec && x < 0)
182 (integer x <> char '#')
183 pprLit _ (WordPrimL x) = integer x <> text "##"
184 pprLit i (FloatPrimL x) = parensIf (i > noPrec && x < 0)
185 (float (fromRational x) <> char '#')
186 pprLit i (DoublePrimL x) = parensIf (i > noPrec && x < 0)
187 (double (fromRational x) <> text "##")
188 pprLit i (IntegerL x) = parensIf (i > noPrec && x < 0) (integer x)
189 pprLit _ (CharL c) = text (show c)
190 pprLit _ (StringL s) = pprString s
191 pprLit _ (StringPrimL s) = pprString (bytesToString s) <> char '#'
192 pprLit i (RationalL rat) = parensIf (i > noPrec) $ rational rat
193
194 bytesToString :: [Word8] -> String
195 bytesToString = map (chr . fromIntegral)
196
197 pprString :: String -> Doc
198 -- Print newlines as newlines with Haskell string escape notation,
199 -- not as '\n'. For other non-printables use regular escape notation.
200 pprString s = vcat (map text (showMultiLineString s))
201
202 ------------------------------
203 instance Ppr Pat where
204 ppr = pprPat noPrec
205
206 pprPat :: Precedence -> Pat -> Doc
207 pprPat i (LitP l) = pprLit i l
208 pprPat _ (VarP v) = pprName' Applied v
209 pprPat _ (TupP ps) = parens $ sep $ punctuate comma $ map ppr ps
210 pprPat _ (UnboxedTupP ps) = hashParens $ sep $ punctuate comma $ map ppr ps
211 pprPat i (ConP s ps) = parensIf (i >= appPrec) $ pprName' Applied s
212 <+> sep (map (pprPat appPrec) ps)
213 pprPat _ (ParensP p) = parens $ pprPat noPrec p
214 pprPat i (UInfixP p1 n p2)
215 = parensIf (i > unopPrec) (pprPat unopPrec p1 <+>
216 pprName' Infix n <+>
217 pprPat unopPrec p2)
218 pprPat i (InfixP p1 n p2)
219 = parensIf (i >= opPrec) (pprPat opPrec p1 <+>
220 pprName' Infix n <+>
221 pprPat opPrec p2)
222 pprPat i (TildeP p) = parensIf (i > noPrec) $ char '~' <> pprPat appPrec p
223 pprPat i (BangP p) = parensIf (i > noPrec) $ char '!' <> pprPat appPrec p
224 pprPat i (AsP v p) = parensIf (i > noPrec) $ ppr v <> text "@"
225 <> pprPat appPrec p
226 pprPat _ WildP = text "_"
227 pprPat _ (RecP nm fs)
228 = parens $ ppr nm
229 <+> braces (sep $ punctuate comma $
230 map (\(s,p) -> ppr s <+> equals <+> ppr p) fs)
231 pprPat _ (ListP ps) = brackets $ sep $ punctuate comma $ map ppr ps
232 pprPat i (SigP p t) = parensIf (i > noPrec) $ ppr p <+> text "::" <+> ppr t
233 pprPat _ (ViewP e p) = parens $ pprExp noPrec e <+> text "->" <+> pprPat noPrec p
234
235 ------------------------------
236 instance Ppr Dec where
237 ppr = ppr_dec True
238
239 ppr_dec :: Bool -- declaration on the toplevel?
240 -> Dec
241 -> Doc
242 ppr_dec _ (FunD f cs) = vcat $ map (\c -> ppr f <+> ppr c) cs
243 ppr_dec _ (ValD p r ds) = ppr p <+> pprBody True r
244 $$ where_clause ds
245 ppr_dec _ (TySynD t xs rhs)
246 = ppr_tySyn empty t (hsep (map ppr xs)) rhs
247 ppr_dec _ (DataD ctxt t xs cs decs)
248 = ppr_data empty ctxt t (hsep (map ppr xs)) cs decs
249 ppr_dec _ (NewtypeD ctxt t xs c decs)
250 = ppr_newtype empty ctxt t (sep (map ppr xs)) c decs
251 ppr_dec _ (ClassD ctxt c xs fds ds)
252 = text "class" <+> pprCxt ctxt <+> ppr c <+> hsep (map ppr xs) <+> ppr fds
253 $$ where_clause ds
254 ppr_dec _ (InstanceD ctxt i ds) = text "instance" <+> pprCxt ctxt <+> ppr i
255 $$ where_clause ds
256 ppr_dec _ (SigD f t) = ppr f <+> text "::" <+> ppr t
257 ppr_dec _ (ForeignD f) = ppr f
258 ppr_dec _ (InfixD fx n) = pprFixity n fx
259 ppr_dec _ (PragmaD p) = ppr p
260 ppr_dec isTop (FamilyD flav tc tvs k)
261 = ppr flav <+> maybeFamily <+> ppr tc <+> hsep (map ppr tvs) <+> maybeKind
262 where
263 maybeFamily | isTop = text "family"
264 | otherwise = empty
265
266 maybeKind | (Just k') <- k = text "::" <+> ppr k'
267 | otherwise = empty
268 ppr_dec isTop (DataInstD ctxt tc tys cs decs)
269 = ppr_data maybeInst ctxt tc (sep (map pprParendType tys)) cs decs
270 where
271 maybeInst | isTop = text "instance"
272 | otherwise = empty
273 ppr_dec isTop (NewtypeInstD ctxt tc tys c decs)
274 = ppr_newtype maybeInst ctxt tc (sep (map pprParendType tys)) c decs
275 where
276 maybeInst | isTop = text "instance"
277 | otherwise = empty
278 ppr_dec isTop (TySynInstD tc eqns)
279 | [TySynEqn tys rhs] <- eqns
280 = ppr_tySyn maybeInst tc (sep (map pprParendType tys)) rhs
281 | otherwise
282 = hang (text "type instance where")
283 nestDepth (vcat (map ppr_eqn eqns))
284 where
285 maybeInst | isTop = text "instance"
286 | otherwise = empty
287 ppr_eqn (TySynEqn lhs rhs)
288 = ppr tc <+> sep (map pprParendType lhs) <+> text "=" <+> ppr rhs
289
290 ppr_data :: Doc -> Cxt -> Name -> Doc -> [Con] -> [Name] -> Doc
291 ppr_data maybeInst ctxt t argsDoc cs decs
292 = sep [text "data" <+> maybeInst
293 <+> pprCxt ctxt
294 <+> ppr t <+> argsDoc,
295 nest nestDepth (sep (pref $ map ppr cs)),
296 if null decs
297 then empty
298 else nest nestDepth
299 $ text "deriving"
300 <+> parens (hsep $ punctuate comma $ map ppr decs)]
301 where
302 pref :: [Doc] -> [Doc]
303 pref [] = [] -- No constructors; can't happen in H98
304 pref (d:ds) = (char '=' <+> d):map (char '|' <+>) ds
305
306 ppr_newtype :: Doc -> Cxt -> Name -> Doc -> Con -> [Name] -> Doc
307 ppr_newtype maybeInst ctxt t argsDoc c decs
308 = sep [text "newtype" <+> maybeInst
309 <+> pprCxt ctxt
310 <+> ppr t <+> argsDoc,
311 nest 2 (char '=' <+> ppr c),
312 if null decs
313 then empty
314 else nest nestDepth
315 $ text "deriving"
316 <+> parens (hsep $ punctuate comma $ map ppr decs)]
317
318 ppr_tySyn :: Doc -> Name -> Doc -> Type -> Doc
319 ppr_tySyn maybeInst t argsDoc rhs
320 = text "type" <+> maybeInst <+> ppr t <+> argsDoc <+> text "=" <+> ppr rhs
321
322 ------------------------------
323 instance Ppr FunDep where
324 ppr (FunDep xs ys) = hsep (map ppr xs) <+> text "->" <+> hsep (map ppr ys)
325 ppr_list [] = empty
326 ppr_list xs = char '|' <+> sep (punctuate (text ", ") (map ppr xs))
327
328 ------------------------------
329 instance Ppr FamFlavour where
330 ppr DataFam = text "data"
331 ppr TypeFam = text "type"
332
333 ------------------------------
334 instance Ppr Foreign where
335 ppr (ImportF callconv safety impent as typ)
336 = text "foreign import"
337 <+> showtextl callconv
338 <+> showtextl safety
339 <+> text (show impent)
340 <+> ppr as
341 <+> text "::" <+> ppr typ
342 ppr (ExportF callconv expent as typ)
343 = text "foreign export"
344 <+> showtextl callconv
345 <+> text (show expent)
346 <+> ppr as
347 <+> text "::" <+> ppr typ
348
349 ------------------------------
350 instance Ppr Pragma where
351 ppr (InlineP n inline rm phases)
352 = text "{-#"
353 <+> ppr inline
354 <+> ppr rm
355 <+> ppr phases
356 <+> ppr n
357 <+> text "#-}"
358 ppr (SpecialiseP n ty inline phases)
359 = text "{-# SPECIALISE"
360 <+> maybe empty ppr inline
361 <+> ppr phases
362 <+> sep [ ppr n <+> text "::"
363 , nest 2 $ ppr ty ]
364 <+> text "#-}"
365 ppr (SpecialiseInstP inst)
366 = text "{-# SPECIALISE instance" <+> ppr inst <+> text "#-}"
367 ppr (RuleP n bndrs lhs rhs phases)
368 = sep [ text "{-# RULES" <+> pprString n <+> ppr phases
369 , nest 4 $ ppr_forall <+> ppr lhs
370 , nest 4 $ char '=' <+> ppr rhs <+> text "#-}" ]
371 where ppr_forall | null bndrs = empty
372 | otherwise = text "forall"
373 <+> fsep (map ppr bndrs)
374 <+> char '.'
375
376 ------------------------------
377 instance Ppr Inline where
378 ppr NoInline = text "NOINLINE"
379 ppr Inline = text "INLINE"
380 ppr Inlinable = text "INLINABLE"
381
382 ------------------------------
383 instance Ppr RuleMatch where
384 ppr ConLike = text "CONLIKE"
385 ppr FunLike = empty
386
387 ------------------------------
388 instance Ppr Phases where
389 ppr AllPhases = empty
390 ppr (FromPhase i) = brackets $ int i
391 ppr (BeforePhase i) = brackets $ char '~' <> int i
392
393 ------------------------------
394 instance Ppr RuleBndr where
395 ppr (RuleVar n) = ppr n
396 ppr (TypedRuleVar n ty) = parens $ ppr n <+> text "::" <+> ppr ty
397
398 ------------------------------
399 instance Ppr Clause where
400 ppr (Clause ps rhs ds) = hsep (map (pprPat appPrec) ps) <+> pprBody True rhs
401 $$ where_clause ds
402
403 ------------------------------
404 instance Ppr Con where
405 ppr (NormalC c sts) = ppr c <+> sep (map pprStrictType sts)
406 ppr (RecC c vsts)
407 = ppr c <+> braces (sep (punctuate comma $ map pprVarStrictType vsts))
408 ppr (InfixC st1 c st2) = pprStrictType st1
409 <+> pprName' Infix c
410 <+> pprStrictType st2
411 ppr (ForallC ns ctxt con) = text "forall" <+> hsep (map ppr ns)
412 <+> char '.' <+> sep [pprCxt ctxt, ppr con]
413
414 ------------------------------
415 pprVarStrictType :: (Name, Strict, Type) -> Doc
416 -- Slight infelicity: with print non-atomic type with parens
417 pprVarStrictType (v, str, t) = ppr v <+> text "::" <+> pprStrictType (str, t)
418
419 ------------------------------
420 pprStrictType :: (Strict, Type) -> Doc
421 -- Prints with parens if not already atomic
422 pprStrictType (IsStrict, t) = char '!' <> pprParendType t
423 pprStrictType (NotStrict, t) = pprParendType t
424 pprStrictType (Unpacked, t) = text "{-# UNPACK #-} !" <> pprParendType t
425
426 ------------------------------
427 pprParendType :: Type -> Doc
428 pprParendType (VarT v) = ppr v
429 pprParendType (ConT c) = ppr c
430 pprParendType (TupleT 0) = text "()"
431 pprParendType (TupleT n) = parens (hcat (replicate (n-1) comma))
432 pprParendType (UnboxedTupleT n) = hashParens $ hcat $ replicate (n-1) comma
433 pprParendType ArrowT = parens (text "->")
434 pprParendType ListT = text "[]"
435 pprParendType (LitT l) = pprTyLit l
436 pprParendType (PromotedT c) = text "'" <> ppr c
437 pprParendType (PromotedTupleT 0) = text "'()"
438 pprParendType (PromotedTupleT n) = quoteParens (hcat (replicate (n-1) comma))
439 pprParendType PromotedNilT = text "'[]"
440 pprParendType PromotedConsT = text "(':)"
441 pprParendType StarT = char '*'
442 pprParendType ConstraintT = text "Constraint"
443 pprParendType other = parens (ppr other)
444
445 instance Ppr Type where
446 ppr (ForallT tvars ctxt ty)
447 = text "forall" <+> hsep (map ppr tvars) <+> text "."
448 <+> sep [pprCxt ctxt, ppr ty]
449 ppr (SigT ty k) = ppr ty <+> text "::" <+> ppr k
450 ppr ty = pprTyApp (split ty)
451
452 pprTyApp :: (Type, [Type]) -> Doc
453 pprTyApp (ArrowT, [arg1,arg2]) = sep [pprFunArgType arg1 <+> text "->", ppr arg2]
454 pprTyApp (ListT, [arg]) = brackets (ppr arg)
455 pprTyApp (TupleT n, args)
456 | length args == n = parens (sep (punctuate comma (map ppr args)))
457 pprTyApp (PromotedTupleT n, args)
458 | length args == n = quoteParens (sep (punctuate comma (map ppr args)))
459 pprTyApp (fun, args) = pprParendType fun <+> sep (map pprParendType args)
460
461 pprFunArgType :: Type -> Doc -- Should really use a precedence argument
462 -- Everything except forall and (->) binds more tightly than (->)
463 pprFunArgType ty@(ForallT {}) = parens (ppr ty)
464 pprFunArgType ty@((ArrowT `AppT` _) `AppT` _) = parens (ppr ty)
465 pprFunArgType ty@(SigT _ _) = parens (ppr ty)
466 pprFunArgType ty = ppr ty
467
468 split :: Type -> (Type, [Type]) -- Split into function and args
469 split t = go t []
470 where go (AppT t1 t2) args = go t1 (t2:args)
471 go ty args = (ty, args)
472
473 pprTyLit :: TyLit -> Doc
474 pprTyLit (NumTyLit n) = integer n
475 pprTyLit (StrTyLit s) = text (show s)
476
477 instance Ppr TyLit where
478 ppr = pprTyLit
479
480 ------------------------------
481 instance Ppr TyVarBndr where
482 ppr (PlainTV nm) = ppr nm
483 ppr (KindedTV nm k) = parens (ppr nm <+> text "::" <+> ppr k)
484
485 ------------------------------
486 pprCxt :: Cxt -> Doc
487 pprCxt [] = empty
488 pprCxt [t] = ppr t <+> text "=>"
489 pprCxt ts = parens (sep $ punctuate comma $ map ppr ts) <+> text "=>"
490
491 ------------------------------
492 instance Ppr Pred where
493 ppr (ClassP cla tys) = ppr cla <+> sep (map pprParendType tys)
494 ppr (EqualP ty1 ty2) = pprFunArgType ty1 <+> char '~' <+> pprFunArgType ty2
495
496 ------------------------------
497 instance Ppr Range where
498 ppr = brackets . pprRange
499 where pprRange :: Range -> Doc
500 pprRange (FromR e) = ppr e <> text ".."
501 pprRange (FromThenR e1 e2) = ppr e1 <> text ","
502 <> ppr e2 <> text ".."
503 pprRange (FromToR e1 e2) = ppr e1 <> text ".." <> ppr e2
504 pprRange (FromThenToR e1 e2 e3) = ppr e1 <> text ","
505 <> ppr e2 <> text ".."
506 <> ppr e3
507
508 ------------------------------
509 where_clause :: [Dec] -> Doc
510 where_clause [] = empty
511 where_clause ds = nest nestDepth $ text "where" <+> vcat (map (ppr_dec False) ds)
512
513 showtextl :: Show a => a -> Doc
514 showtextl = text . map toLower . show
515
516 hashParens :: Doc -> Doc
517 hashParens d = text "(# " <> d <> text " #)"
518
519 quoteParens :: Doc -> Doc
520 quoteParens d = text "'(" <> d <> text ")"
521