[Haskell-cafe] Best way to build strings?

Tomasz Zielonka tomasz.zielonka at gmail.com
Thu Jul 21 03:24:39 EDT 2005


On Thu, Jul 21, 2005 at 04:55:15PM +1000, Bernard Pope wrote:
> On Wed, 2005-07-20 at 17:06 +0100, Andy Gimblett wrote:
> >     show (Prefix l p) = "(" ++ l ++ "->" ++ show p ++ ")"
> >     show (External p q) = "(" ++ show p ++ " [] " ++ show q ++ ")"
> > 
> > but to me the extensive use of ++ is not particularly readable.
> 
> It is also inefficient because append has complexity proportional to the
> length of its left argument. That's why the Prelude defines:
> 
>    type ShowS = String -> String
> 
> and functions like showsPrec, shows, showChar

It's not that bad in this case, because ++ is right-associative.

Best regards
Tomasz


More information about the Haskell-Cafe mailing list