[web-devel] Re: [Haskell-cafe] Google Summer of Code: BlazeHTML RFC
Bas van Dijk
v.dijk.bas at gmail.com
Thu May 27 05:36:30 EDT 2010
On Thu, May 27, 2010 at 10:48 AM, Jasper Van der Jeugt
<jaspervdj at gmail.com> wrote:
>> How about also providing an enumerator back-end?
>> http://hackage.haskell.org/packages/archive/iteratee/0.3.5/doc/html/Data-Iteratee-Base.html#t%3AEnumeratorGM
>>
>> Then your library can integrate more easily with the snap framework:
>> http://snapframework.com
>
> Sure, I can do that. But I already tested integration with the snap
> framework, the best path here seems to call the `writeLBS` function
> from the snap framework on the `L.ByteString` that BlazeHtml produces
> (`writeLBS` internally uses an enumerator).
I think it's worth analyzing if using enumerators directly gives a
significant performance improvement over converting from lazy
ByteStrings.
Looking a the conversion functions in the snap framework it looks like
we can avoid some intermediate lists for one:
writeLBS :: L.ByteString -> Snap ()
writeLBS s = addToOutput $ enumLBS s
addToOutput :: (forall a . Enumerator a) -> Snap ()
addToOutput enum = modifyResponse $ modifyResponseBody (>. enum)
enumLBS :: (Monad m) => L.ByteString -> Enumerator m a
enumLBS lbs iter = foldM k iter enums
where
enums = map (enumPure1Chunk . WrapBS) $ L.toChunks lbs
k i e = e i
-- from iteratee:
enumPure1Chunk :: (SC.StreamChunk s el, Monad m) =>
s el ->
EnumeratorGM s el m a
enumPure1Chunk str iter = runIter iter (Chunk str) >>= checkIfDone return
Regards,
Bas
More information about the web-devel
mailing list