Re: [Haskell-cafe] Best way to build strings?

Hello there,
I'm very fond of Python's interpolation approach, where we'd have something like the following for the External case:
def __str__(self): return "(%s [] %s)" % (self.p, self.q)
are you familiar with C's printf procedure? It's where that kind of notation comes from. You can use Text.Printf which provides the function printf :: PrintfType r => String -> r Thus you can write show (Prefix l p) = printf "(%s->%s)" l q show (External p q) = printf "(%s [] %s)" p q Alas, I couldn't test it, because the Text module seems to not be installed on my computer (sad thing not being the admin, isn't it?) Nevertheless, take a look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/Text.Printf.html Regards, Frank-Andre Riess
participants (1)
-
Frank-Andre Riess