The bug is in parsedL, I marked the line with "bug here" in a comment.
`atEndOfParserInput`
is used with evalStateT not runStateT. `atEndOfParserInput` puts elements
back into the state and `evalStateT` is throwing it way.
parsedL :: (Monad m, ParserInput a) => Attoparsec.Parser a b
-- ^ Attoparsec parser -> Producer a m r -- ^ Raw input
-> Producer (Int, b) m (Either (ParsingError, Producer a m r)
r)parsedL parser = go where go p0 = do mr <- lift $
S.evalStateT atEndOfParserInput p0 -- bug here case mr of
Just r -> return (Right r) Nothing -> do (x, p1)
<- lift $ S.runStateT (parseL parser) p0 case x of
Left e -> return (Left (e, p1)) Right a -> yield a
>> go p1
It just needs to propagate state from `atEndOfParserInput` to `parseL` like so:
parsedL parser = go where
go p0 = do
(mr, p1) <- lift $ S.runStateT atEndOfParserInput p0
case mr of
Just r -> return (Right r)
Nothing -> do
(x, p2) <- lift $ S.runStateT (parseL parser) p1
case x of
Left e -> return (Left (e, p2))
Right a -> yield a >> go p2
I am going to do a pull request in the moment for the repo.
Patrick
On Sat, Mar 15, 2014 at 12:10 PM, Michael Thompson <
[email protected]> wrote:
> I should have stated the obvious that pipe2 fails because it is interested
> in chunk boundaries.
> Is this the intended behavior? We can see the difference if we run
>
> pipes2a h = do let pipe = P.parsed entry (PB.chunksOf' 10 $
> PB.fromHandle h >-> PB.drop 1) >> return ()
> P.fold (+) 0 id pipe >>= print
>
> instead. Then we get close to the correct result.
>
> $ time ./iostreamsbench pipes2a
> 12357925369121
>
> real 0m11.048s
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haskell Pipes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
>
--
Patrick Wheeler
[email protected]
[email protected]
[email protected]
--
You received this message because you are subscribed to the Google Groups
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].