[Haskell-cafe] Best way to build strings?
Vadim Konovalov
vadim at vkonovalov.ru
Sun Jul 24 04:21:02 EDT 2005
>I wish to toss out a new thought. To that end let me blow up the example
>to underline a scalability issue:
>
>A. q ++ " " ++ a ++ " " ++ z ++ " [" ++ m ++ " -> " ++ k ++ " |" ++ p ++ "| "
> ++ g ++ " -> " ++ c ++ "] " ++ h ++ " " ++ b ++ " " ++ f ++ " " ++ i
>B. printf "%s %s %s [%s -> %s |%s| %s -> %s] %s %s %s %s" q a z m k p g c h
> b f i
>
>B looks clearer because without parsing you can see that the output will
>contain a |blah| between two blah->blah's inside square brackets, etc.
>
>A looks clearer because without counting you can see that p is the
>thing that will go into |blah|, the first blah->blah will be m->k,
>etc.
>
>The best of both worlds may be something like the notation in the HOL
>theorem prover:
>
>``^q ^a ^z [^m -> ^k |^p| ^g -> ^c] ^h ^b ^f ^i``
>
>Do you agree that this is much better?
>
>
this syntax is used in Perl, and, IMHO, is very convenient.
Also very convenient are HERE-docs, when user should not bother about
escaping and concatenating of large strings.
More information about the Haskell-Cafe
mailing list