[Haskell-cafe] RE: Pretty Print, text or ++?

Paul Keir pkeir at dcs.gla.ac.uk
Fri Aug 15 10:07:20 EDT 2008


Awesome! Thanks to you all. I'll start with

hsep[map a, b, c, d]

and then I can try changing hsep for other things.

Paul


-----Original Message-----
From: Benedikt Huber [mailto:benjovi at gmx.net]
Sent: Fri 15/08/2008 14:53
To: Paul Keir
Cc: haskell-cafe at haskell.org
Subject: Re: Pretty Print, text or ++?
 
Paul Keir schrieb:
 > Hi there,
 >
 > I'm writing a pretty printer using the Text.PrettyPrint library, and
 > there's a pattern I'm coming across quite often. Does anyone know 
whether,
 >
 > text (a ++ b ++ c ++ d)
 > or
 > text a <+> text b <+> text c <+> text d
 >
 > runs quicker?

Hi Paul,

 > text (a ++ b ++ c ++ d)

is the same as

 > hcat (map text [a,b,c,d])

(horizontal concatenation without seperating spaces)
while

 > text a <+> text b <+> text c <+> text d

corresponds to

 > hsep (map text [a,b,c,d])

or

 > text (unwords [a,b,c,d])

With <+>, hsep or hcat, pretty printing won't choose the best layout -
you tell the pretty printer to layout documents 'beside'.
For autolayout, see sep,cat and the paragraph-fill variants fsep and fcat.

Regarding performance: `unwords` will propably be a little faster 
(untested), but less flexible. There is no asymptotic overhead when 
using the pretty printer.

cheers,
benedikt

 >
 > Cheers,
 > Paul
 >
 >
 > ------------------------------------------------------------------------
 >
 > _______________________________________________
 > Haskell-Cafe mailing list
 > Haskell-Cafe at haskell.org
 > http://www.haskell.org/mailman/listinfo/haskell-cafe


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080815/5d7846c9/attachment.htm


More information about the Haskell-Cafe mailing list