No subject


Sat Nov 26 14:22:34 GMT 2011


be the desired type most of the time anyway.

I guess my question for Conrad is, do you actually use a stream of
[Word8]?  If not, I would say to stick with ByteStrings.  If you do,
then it still may make sense to use just ByteStrings and convert with
mapChunks where necessary.

As to the type class, to my knowledge it doesn't exist.  I think
ByteStrings make sense for C bindings.  Rather than generalizing the
type of enumInflate, I would prefer explicitly converting the output
with mapChunks (or more complex functions when necessary).  There's a
danger of too much generalization.  If all the input and output types
are polymorphic, then users need to provide type annotations
everywhere.  I think it's both simpler and more intuitive to have some
monomorphic types to anchor code and expectations.  In line with this,
I'm considering (but not completely sold on) changing enumFile*
functions to generate only ByteString streams in future releases.

John

On Fri, Nov 11, 2011 at 4:48 AM, Michael Baikov <manpacket at gmail.com> wrote=
:
> Are you sure that operating on [Word8] where it represents compressed
> stream makes sence? To get benefits from compression size of data
> should be quite large and operating on large lists of binary data is a
> very good way to destroy the performance. So the idea =A0should be
> operating on ByteStrings until you need data extracted and extract
> data into that format you really want. So making it into generic case
> is stupid, and if user really wants to destroy it's performance - it
> is easy to achieve using threadDelay or mapStream B.unpack
>
> Also enumInflate in iteratee-compress *should* be implemented in terms
> of Enumeratee instread of Enumerator, because it's idea is to
> transform data stream from one type to another and not the iteratee
> itself.
>
>
> On Fri, Nov 11, 2011 at 12:29 PM, Conrad Parker <conrad at metadecks.org> wr=
ote:
>> Hi,
>>
>> I recently converted zoom-cache to use (I.Nullable, LL.ListLike s
>> Word8) constraints for byte streams. I then added support for
>> compressed data blocks, using enumInflate from iteratee-compress:
>>
>> enumInflate :: MonadIO m =3D> Format -> DecompressParams -> Enumerator
>> ByteString m a
>>
>> In order to use that unmodified, I wanted a function of type (Iteratee
>> ByteString m a -> Iteratee s m a), and ended up writing a simple
>> typeclass for ByteStringLike streams:
>>
>>
>> class (I.Nullable s, LL.ListLike s Word8) =3D> ByteStringLike s where
>> =A0 =A0likeFromByteString :: ByteString -> s
>> =A0 =A0likeToByteString =A0 :: s -> ByteString
>>
>> instance ByteStringLike [Word8] where
>> =A0 =A0likeFromByteString =3D B.unpack
>> =A0 =A0likeToByteString =A0 =3D B.pack
>>
>> instance ByteStringLike ByteString where
>> =A0 =A0likeFromByteString =3D id
>> =A0 =A0likeToByteString =A0 =3D id
>>
>>
>> allowing the desired conversion function:
>>
>>
>> iterToByteStringLike :: (I.Nullable s, LL.ListLike s Word8,
>> ByteStringLike s, Monad m)
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D> Iteratee ByteString m a -> =
Iteratee s m a
>> iterToByteStringLike =3D I.joinI . I.mapChunks likeToByteString
>>
>>
>> This all seems a bit circuitous.
>>
>> 1) Does a similar typeclass already exist?
>>
>> 2) Is there a simpler way to use enumInflate from an arbitrary byte stre=
am?
>>
>> 3) It would be nice to just generalize the type of enumInflate, but it
>> binds to the zlib C library and expects byte buffers, hence the direct
>> ByteString interface; it would have to do something similar
>> internally. Would these to/from iteratee conversion functions be
>> generally useful for the Iteratee library?
>>
>> Code for Data.Iteratee.ByteStringLike is here:
>> https://github.com/kfish/zoom-cache/blob/zlib/Data/Iteratee/ByteStringLi=
ke.hs
>>
>> cheers,
>>
>> Conrad.
>>
>> _______________________________________________
>> Iteratee mailing list
>> Iteratee at projects.haskell.org
>> http://projects.haskell.org/cgi-bin/mailman/listinfo/iteratee
>>
>
> _______________________________________________
> Iteratee mailing list
> Iteratee at projects.haskell.org
> http://projects.haskell.org/cgi-bin/mailman/listinfo/iteratee
>



More information about the Iteratee mailing list