2 % (c) The GRASP Project, Glasgow University, 1992-1996
4 \section[Outputable]{Classes for pretty-printing}
6 Defines classes for pretty-printing and forcing, both forms of
10 #include "HsVersions.h"
13 Outputable(..), -- class
15 interppSP, interpp'SP,
18 ifPprShowAll, ifnotPprShowAll,
24 import PprStyle ( PprStyle(..) )
26 import Util ( cmpPString )
29 %************************************************************************
31 \subsection[Outputable-class]{The @Outputable@ class}
33 %************************************************************************
36 class Outputable a where
37 ppr :: PprStyle -> a -> Pretty
41 -- the ppSep in the ppInterleave puts in the spaces
42 -- Death to ppSep! (WDP 94/11)
44 interppSP :: Outputable a => PprStyle -> [a] -> Pretty
45 interppSP sty xs = ppIntersperse ppSP (map (ppr sty) xs)
47 interpp'SP :: Outputable a => PprStyle -> [a] -> Pretty
49 = ppIntersperse sep (map (ppr sty) xs)
51 sep = ppBeside ppComma ppSP
55 ifPprDebug sty p = case sty of PprDebug -> p ; _ -> ppNil
56 ifPprShowAll sty p = case sty of PprShowAll -> p ; _ -> ppNil
57 ifPprInterface sty p = case sty of PprInterface -> p ; _ -> ppNil
59 ifnotPprForUser sty p = case sty of PprForUser -> ppNil ; _ -> p
60 ifnotPprShowAll sty p = case sty of PprShowAll -> ppNil ; _ -> p
64 instance Outputable Bool where
65 ppr sty True = ppPStr SLIT("True")
66 ppr sty False = ppPStr SLIT("False")
68 instance (Outputable a) => Outputable [a] where
70 ppBesides [ ppLbrack, ppInterleave ppComma (map (ppr sty) xs), ppRbrack ]
72 instance (Outputable a, Outputable b) => Outputable (a, b) where
74 ppHang (ppBesides [ppLparen, ppr sty x, ppComma]) 4 (ppBeside (ppr sty y) ppRparen)
76 -- ToDo: may not be used
77 instance (Outputable a, Outputable b, Outputable c) => Outputable (a, b, c) where
79 ppSep [ ppBesides [ppLparen, ppr sty x, ppComma],
80 ppBeside (ppr sty y) ppComma,
81 ppBeside (ppr sty z) ppRparen ]