[Haskell-cafe] Arguments against an hypothetical Data.ByteString.Generic?

Yves Parès yves.pares at gmail.com
Tue Mar 27 21:46:46 CEST 2012

Hi Bas,

Yes, thank you to remind me of that, I remember now having seen the project.
Strict ByteStrings being an alias to Vector Word8 is a good idea (are
bytestrings are already implemented exactly like
Data.Vector.Storable.Vector). But in that case we could use the API of
vector for bytestrings (the bytestring API would be provided only for
backwards compatibility, right?).

Does vector-bytestring plans to be the new implementation for bytestrings
in the end or is it a side-package?

> In an ideal world we would have a Lazy type family which for each type
> of vector would return its lazy version

What about a type like:

data Vector v a = Empty | Chuck {-# UNPACK #-} !(v a) (Vector v a)

GHC accepts it.
And then every function for lazy vectors can then be written like:

import qualified Data.Vector.Generic as G (Vector(..))

cons :: (G.Vector v) => a -> Vector v a -> Vector v a
cons x v = ...

and also (even better):

instance (G.Vector v) => G.Vector (Vector v) where
    cons x v = ...

Just make aliases to follow the API, for instance in Data.Vector.Lazy:

import qualified Data.Vector.Lazy.Internal as L
import qualified Data.Vector as V

type Vector a = L.Vector V.Vector a

Le 27 mars 2012 20:38, Bas van Dijk <v.dijk.bas at gmail.com> a écrit :

> On 27 March 2012 11:00, Yves Parès <yves.pares at gmail.com> wrote:
> > Hello,
> >
> > As vector provides a class generalizing all flavours
> > (Data.Vector.Generic.Vector), it occurs to me that the same could be done
> > for ByteString. Then, packages based on it would have the choice between
> > hardcoded and generic, they wouldn't have to duplicate a module to handle
> > both strict and lazy versions, as (with the exception of functions for
> > communication with C code) they already provide the same API.
> > I would be willing to make it, it's a concern I've had in mind for a long
> > time, but as I'm pretty sure the idea isn't new, I would very much like
> to
> > know if and what arguments (related to performance maybe ? I don't
> know...)
> > were raised against that.
> It's not entirely what you need but are you aware of my
> vector-bytestring library?
> http://hackage.haskell.org/package/vector-bytestring
> It doesn't (yet) abstract over strict and lazy ByteStrings. But that
> would be a nice addition!
> In an ideal world we would have a Lazy type family which for each type
> of vector would return its lazy version (where the vector is unpacked
> in the cons cell). Then we would need your generic API for working
> with both lazy and strict vectors.
> Regards,
> Bas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120327/226f1b8e/attachment.htm>

More information about the Haskell-Cafe mailing list