[Haskell-cafe] Pretty-printer for Text

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Wed Oct 27 05:27:48 EDT 2010


On 27 October 2010 20:13, Stephen Tetley <stephen.tetley at gmail.com> wrote:
> On 27 October 2010 09:32, Ivan Lazar Miljenovic
> <ivan.miljenovic at gmail.com> wrote:
>
>> I had to write my own [1] for two reasons: 1) I needed to be able to
>> differentiate between quoted and un-quoted values, and 2) some of the
>> ways values get pretty-printed are different than just "text . show",
>> which is what all the default instances of the Pretty classes are
>> (with the exception of String).  It's this second point that I would
>> wonder how many people would use a default Pretty class: just because
>> I want to print String values one way, does that you mean you should
>> print them that way as well?
>
> If you were specifically working around issues of quoting, maybe there
> would have been room for an alternative design where an Identifier
> datatype had two constructors one for simple strings and one for
> quoted ones.

Well, in my case it's because Dot attributes need to have their values
in quotes when they contain spaces, etc.  As such, you have these
situations:

* ` DotNode 1 [Label $ StrLabel "foo"] ' is printed as ` 1 [label=foo] '

* ` DotNode 2 [Label $ StrLabel "bar baz"] ' is printed as ` 2
[label="bar baz"] '

Now, I _could_ have just quoted everything, but I tried to make the
generated Dot code as "correct" as possible.

> In a nutshell, wl-pprint seems to have got the interface 'right' for
> my tastes. I like having both named primitive printers and a Pretty
> class. If I want printers for ShowS types or for Docs that don't need
> page formatting I always copy Wl-pprint's interface.

OK, I'll keep the class in as well.

What about my other queries (e.g. to keep SimpleDoc or not)?

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list