[Haskell-cafe] Best way to build strings?
A.M.Gimblett at swansea.ac.uk
Wed Jul 20 12:06:23 EDT 2005
A small stylistic question: what's the "best" way to build strings
containing other values? For example, I have:
data Process = Stop |
Prefix String Process |
External Process Process
instance Show Process where
show Stop = "Stop"
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.
I'm very fond of Python's interpolation approach, where we'd have
something like the following for the External case:
return "(%s  %s)" % (self.p, self.q)
which to me seems clearer, or at least easier to work out roughly what
the string's going to look like. (The %s does an implicit "convert to
Is there a facility like this in Haskell? Or something else I should
be using, other than lots of ++ ?
Computer Science Department
University of Wales Swansea
More information about the Haskell-Cafe