[Haskell-cafe] Clever generic ByteString hack?

John Goerzen jgoerzen at complete.org
Wed Jul 5 09:16:13 EDT 2006


On Wed, Jul 05, 2006 at 12:25:53PM +0100, Duncan Coutts wrote:
> > different types of input?  I'd rather avoid having 3 versions, that are
> > exactly the same except for imports.
> 
> People sometimes talk about doing a type class to cover string like
> modules.

Yes, that makes sense to me.  I was sorta hoping to avoid having to say
something like:

instance StringLike B.ByteString where
     vlength = B.length
     vcons = B.cons
     ...  with about 50 of these lines ...


> What functions are you thinking of btw? We may want to include them in
> the ByteString modules anyway (possibly directly rather than in terms of
> other functions, to take advantage of tricks with the representation).

Most everything here:

http://quux.org/devel/missingh/html/MissingH-Str.html

The appropriate bits from:

http://quux.org/devel/missingh/html/MissingH-List.html

And perhaps even:

http://quux.org/devel/missingh/html/MissingH-Str-CSV.html

Also, it would be nice to see direct regexp support in ByteString.  It
seems ugly to have to convert to a String just to pass it back to C.

But even if you did implement all of that, I think there is still
utility in having a generic typeclass that can take any of the three
string-like types that we have in Haskell these days.  Otherwise, you
are going to see library fracturization -- some code works with Strings,
some with ByteStrings, some with lazy ByteStrings, and woe to the
programmer that has to integrate all this mess.

(OCaml has this problem in a big way with its lists vs. Streams and
built-in handicapped IO vs. Posix IO)

-- John



More information about the Haskell-Cafe mailing list