[Haskell-cafe] ANNOUNCE: vector-bytestring-0.0.0.0
Bas van Dijk
v.dijk.bas at gmail.com
Mon Oct 17 21:04:10 CEST 2011
On 17 October 2011 20:15, Yves Parès <limestrael at gmail.com> wrote:
> It's a good question, I don't think there is something in the vector library
> that can handle chunks of vectors...
Yes I forgot about lazy bytestrings when writing that. Of course
vector-bytestring does provide lazy ByteStrings.
> If both lazy and strict bytestrings are to be generalized, it would at last
> permit to have a single interface to them, thanks to Data.Vector.Generic,
> and no longer two identical interfaces in separate modules, which forces to
> duplicate each code which handles bytestrings so that it can deal with the
> two flavours.
It would be an interesting idea to add a chunking vector adapter to
the vector package.
I guess it will look something like this:
data Chunks v a = Empty | Chunk {-# UNPACK #-} !(v a) (Chunks v a)
foldrChunks :: (v a -> b -> b) -> b -> Chunks v a -> b
foldrChunks f z = go
where go Empty = z
go (Chunk c cs) = f c (go cs)
{-# INLINE foldrChunks #-}
foldlChunks :: (b -> v a -> b) -> b -> Chunks v a -> b
foldlChunks f z = go z
where go !a Empty = a
go !a (Chunk c cs) = go (f a c) cs
{-# INLINE foldlChunks #-}
Giving it an instance for Data.Vector.Generic.Base.Vector should be
easy right? Anyone up for the job?
Then I can replace my custom lazy ByteStrings with:
type ByteString = Chunks Vector Word8
Bas
More information about the Haskell-Cafe
mailing list