[Haskell-cafe] Clever generic ByteString hack?

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Jul 5 07:25:53 EDT 2006

On Wed, 2006-07-05 at 05:58 -0500, John Goerzen wrote: 
> Hi,
> In MissingH, I have a bunch of little functions that operate on lists.
> Some, like uniq (which eliminates duplicate elements in a list), operate
> on (Eq a => [a]) lists.  Others, like strip (which eliminates whitespace
> at the start and end), operate on Strings only.
> Most functions of both types would be useful on ByteStrings and lazy
> ByteStrings.  Most of these functions are written in terms of Data.List
> functions or list primitives that have equivolents in Data.ByteString.
> So, my question is: is there a clever hack available to me so that I
> could have 1 version of each function, and have it work on all three
> 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

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).


More information about the Haskell-Cafe mailing list