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
53 #ifdef USE_ATTACK_PRAGMAS
54 {-# SPECIALIZE interppSP :: PprStyle -> [Id] -> Pretty #-}
55 {-# SPECIALIZE interppSP :: PprStyle -> [TyVar] -> Pretty #-}
57 {-# SPECIALIZE interpp'SP :: PprStyle -> [(Id, Id)] -> Pretty #-}
58 {-# SPECIALIZE interpp'SP :: PprStyle -> [Id] -> Pretty #-}
59 {-# SPECIALIZE interpp'SP :: PprStyle -> [TyVarTemplate] -> Pretty #-}
60 {-# SPECIALIZE interpp'SP :: PprStyle -> [TyVar] -> Pretty #-}
61 {-# SPECIALIZE interpp'SP :: PprStyle -> [Type] -> Pretty #-}
66 ifPprDebug sty p = case sty of PprDebug -> p ; _ -> ppNil
67 ifPprShowAll sty p = case sty of PprShowAll -> p ; _ -> ppNil
68 ifPprInterface sty p = case sty of PprInterface -> p ; _ -> ppNil
70 ifnotPprForUser sty p = case sty of PprForUser -> ppNil ; _ -> p
71 ifnotPprShowAll sty p = case sty of PprShowAll -> ppNil ; _ -> p
75 instance Outputable Bool where
76 ppr sty True = ppPStr SLIT("True")
77 ppr sty False = ppPStr SLIT("False")
79 instance (Outputable a) => Outputable [a] where
81 ppBesides [ ppLbrack, ppInterleave ppComma (map (ppr sty) xs), ppRbrack ]
83 instance (Outputable a, Outputable b) => Outputable (a, b) where
85 ppHang (ppBesides [ppLparen, ppr sty x, ppComma]) 4 (ppBeside (ppr sty y) ppRparen)
87 -- ToDo: may not be used
88 instance (Outputable a, Outputable b, Outputable c) => Outputable (a, b, c) where
90 ppSep [ ppBesides [ppLparen, ppr sty x, ppComma],
91 ppBeside (ppr sty y) ppComma,
92 ppBeside (ppr sty z) ppRparen ]