0
例如,在這樣的代碼:在Haskell中做什麼顯示和渲染?
module Main(letters) where
import Data.List(nub)
import qualified Text.PrettyPrint.HughesPJ as PP
import Text.PrettyPrint.HughesPJ(Doc,text,int,(<>),(<+>),($+$),render)
data Prop a =
LetterP a
| AndP (Prop a) (Prop a)
deriving Eq
class PPLetter a where
ppLetter :: a -> Doc
instance PPLetter Int where
ppLetter a = text ("p"++show a)
instance PPLetter Char where
ppLetter = PP.char
instance PPLetter a => PPLetter [a] where
ppLetter = PP.hcat . (map ppLetter)
class PP a where
pp :: a -> Doc
instance PP Bool where
pp True = text "True"
pp False = text "False"
parens n ([email protected](LetterP _)) = pp term
instance PPLetter a => PP(Prop a) where
pp (LetterP a) = ppLetter a
pp (AndP x y) = PP.sep [ parens 4 x, text "/\\", parens 4 y]
instance PPLetter a => Show (Prop a) where
show x = render (pp x)
main = do
let p = LetterP 1
print p
一個提問時,請更詳細一點。 – fuz 2011-04-16 16:09:10