[Haskell-cafe] ANN: text-printer - abstract interface for text builders/printers
Mikhail Vorozhtsov
mikhail.vorozhtsov at gmail.com
Fri Mar 22 09:46:53 CET 2013
Hello,
I was writing a library for working with IP addresses when I found
myself puzzled with the number of contexts in which the textual
representation of an address could be used: plain strings, bytestring
builders (ASCII/UTF8), text builders, pretty printers, etc. I could've
just written an `addressToString :: Address -> String` function, but
that would be suboptimal: (a) namespace pollution (that's a lot of
*ToString's if you count IPv4/6, network addresses, socket addresses,
etc) and (b) some contexts can take advantage of the fact that textual
representations are ASCII (e.g. UTF8 bytestring builder).
And so the text-printer[1] was born. It is mainly two type classes. One
for injecting text into a monoid, with special methods for ASCII and
UTF-8 characters/strings. The other provides the default injection for
values of a type (think of the `Pretty` type class in pretty printing
libraries), the textual representation is supposed to be simple
(single-line). Plus some convenient combinators and number formatters.
[1] http://hackage.haskell.org/package/text-printer
More information about the Haskell-Cafe
mailing list