
On 11-05-25 08:52 AM, Johan Tibell wrote:
On Wed, May 25, 2011 at 2:01 PM, Ivan Lazar Miljenovic
wrote: With my wl-pprint-text package, Jason Dagit suggested to me on #haskell that it would make sense to make such a pretty-printer be class-based so that the same API could be used for String, ByteString, Text, etc. I'm a bit skeptical of using type classes to abstract over Unicode string types and byte sequence types. The only API shared by the two kind of types is that of a sequence. Things like dot , spaces, etc. don't make much sense on binary data. You must assume that the ByteString contains text in some encoding to make sense of such concepts.
You don't necessarily need spaces and dot to abstract over bytestrings and Unicode string types. They both implement IsString and Monoid classes, as well as operations null, length, isPrefixOf, take, and drop. That's sufficient to implement a generic parser that works on any input type supporting these operations (see [1] for example), though there is some performance cost. I don't see why a pretty-printer should be any more difficult. [1] http://hackage.haskell.org/package/incremental-parser