New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Data.Parser.ParserD.deintercalate #843
Conversation
@specdrake Can you resolve the conflicts? I'll review it after. |
e0b529c
to
4b83436
Compare
4b83436
to
377013b
Compare
Can you take a look at this now? |
deintercalate fld1 prsr1 fld2 prsr2 = | ||
K.toParserK $ | ||
D.deintercalate | ||
fld1 | ||
(K.fromParserK prsr1) | ||
fld2 | ||
(K.fromParserK prsr2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deintercalate fld1 prsr1 fld2 prsr2 = | |
K.toParserK $ | |
D.deintercalate | |
fld1 | |
(K.fromParserK prsr1) | |
fld2 | |
(K.fromParserK prsr2) | |
deintercalate f1 p1 f2 p2 = | |
K.toParserK $ D.deintercalate f1 (K.fromParserK p1) f2 (K.fromParserK p2) |
pinit1 <- pinitial1 | ||
finit2 <- finitial2 | ||
pinit2 <- pinitial2 | ||
return (finit1, pinit1, finit2, pinit2, Parser1, 0::Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the benchmarks, you might want to use a strict state, Tuple6'
pinit2 <- pinitial2 | ||
return (finit1, pinit1, finit2, pinit2, Parser1, 0::Int) | ||
|
||
step (fs1, ps1, fs2, ps2, currentParser, numBuffered) a = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of currentParser
you can probaly simplify this if you use Bool
. Something like isParser1
. Your call. You can try both and check the benchmarks. I suspect they won't differ much though.
st <- pstep1 ps1 a | ||
case st of | ||
Partial n ps1new -> | ||
return $ Partial n (fs1, ps1new, fs2, ps2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the tuple on the same line?
let | ||
newNumBuffered = | ||
if n==0 | ||
then numBuffered + 1 | ||
else numBuffered - n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If numBuffered + 1 - n < 0
there is some flaw in the logic. You should use asserts instead.
Also, shouldn't it be numBuffered + 1 - n
instead of numBuffered - n
?
if n==0 | ||
then numBuffered + 1 | ||
else numBuffered - n | ||
return $ Continue n (fs1, ps1new, fs2, ps2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the tuple on the same line?
Done n result -> do | ||
res1 <- fstep1 fs1 result | ||
pinit1 <- pinitial1 | ||
pinit2 <- pinitial2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are multiple unrequired initializations here.
Looks like ps2
is pinit2
If you don't need both the states at once, you can probably encode the parser state in the constructors themselves.
Parser2, numBuffered) | ||
FL.Done result1 -> do | ||
result2 <- fextract2 fs2 | ||
return $ Done numBuffered (result1, result2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just backtrack n
elements here? Why numBuffered
elements?
-- input definitively rejected by the first parser | ||
pinit1 <- pinitial1 | ||
pinit2 <- pinitial2 | ||
return $ Partial numBuffered (fs1, pinit1, fs2, pinit2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should backtrack numBuffered + 1
elements here instead of numBuffered
?
And restart the buffer count from 0
instead of numBuffered - 1
?
Parser2, numBuffered-1) | ||
-- return $ Done numBuffered (result1, result2) | ||
|
||
Parser2 -> do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments made above apply to this branch.
@@ -59,6 +59,11 @@ benchIOSink value name f = | |||
------------------------------------------------------------------------------- | |||
-- Parsers | |||
------------------------------------------------------------------------------- | |||
{-# INLINE deintercalate #-} | |||
deintercalate :: MonadCatch m => Int -> SerialT m Int -> m ((), ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need benchmarks for ParserD
as well.
-- Left _ -> property False | ||
|
||
deintercalate :: Property | ||
deintercalate = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being tested in Parser
as well. I guess you can skip testing this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the comments. I see some correctness issues but the tests give no failure.
Either I've misunderstood, if so, please revet back by responding to the comments.
Else we probably need more elaborarte tests hitting all the branches.
I see some indentation issues as well. That's not a big deal though.
I'll reindent this in the end. Diffing that with this will probably makes thing clear w.r.t indentation.
I'll try to do this by today. |
I had made the changes but I am unable to benchmarks and tests because of the following errors:
I have tried using |
Superseded by #1600 |
No description provided.