relude-parse icon indicating copy to clipboard operation
relude-parse copied to clipboard

Make list-producing parsers tail recursive

Open mlms13 opened this issue 6 years ago • 2 comments

I know there's a comment in the code, but I figured I'd open a more official ticket since this will probably become an issue in Relude CSV (since parsing an 8000 line CSV file doesn't seem completely out of the question).

I was looking at the MonadRec stuff in PureScript, and I think it's very similar to the trampoline technique that I was porting from Scala to Reason. I may try to do something in Relude proper, which hopefully relude-parse will be able to benefit from.

mlms13 avatar Sep 09 '19 16:09 mlms13

Yeah, exactly - I left all that stuff kind of unimplemented, b/c it looked like if we had MonadRec, we'd be able to more easily re-work all this stuff to be tail recursive.

Once we get there, we should check all the recursive functions in relude-parse and attempt to make them all tail-recursive.

andywhite37 avatar Sep 09 '19 16:09 andywhite37

See relude issue reazen/relude#166 for MonadRec.

The key thing we need for relude-parse is the List.manyRec function, like here: https://github.com/purescript-contrib/purescript-string-parsers/blob/master/src/Text/Parsing/StringParser/Combinators.purs#L52-L53

List.manyRec: https://pursuit.purescript.org/packages/purescript-lists/4.0.1/docs/Data.List#v:manyRec

andywhite37 avatar Sep 19 '19 16:09 andywhite37