Pretty class as alternative for Show class

Christian Maeder Christian.Maeder at dfki.de
Wed Feb 13 09:01:21 EST 2008


John Meacham wrote:
> See my 'Doc' project. which includes both a show alternative class like
> you describe as
> well as a class abstracting different pretty printers.
> 
> http://repetae.net/repos/Doc

Why should I use your DocLike module (instead of
Text.PrettyPrint.HughesPJ directly)?

from module DocLike:

    x <+> y = x <> char ' ' <> y
    x <$> y = x <> char '\n' <> y
    encloseSep l r s ds = enclose l r (hcat $ punctuate s ds)
    enclose l r x   = l <> x <> r
    list            = encloseSep lbracket rbracket comma
    tupled          = encloseSep lparen   rparen  comma
    semiBraces      = encloseSep lbrace   rbrace  semi

1. The indentation is wrong for Doc from your module Pretty (and strings):

*Pretty> text "a" DocLike.<+> (text "b" DocLike.<$> text "c") :: Doc
a b
c

2. encloseSep may produce too long lines without breaks

The HughesPJ output is correct:

*DocLike> P.text "a" <+> (P.text "b" <$> P.text "c")
a b
  c

Cheers Christian


More information about the Libraries mailing list