Parsing recursively with purescript-parsing

Question for @natefaubion , or anyone else:

I wrote a recursive parseMessage function with parsing. The recursion wasn’t working, but then it worked after I applied the fixed point technique from 2. Parsing recursively · Thimoteus/SandScript Wiki · GitHub

Later on, after the upgrade to PureScript 0.15 and the CPS refactor of parsing, I found that in this commit, I was able to get rid of the fixed point and just do naïve recursion for parseMessage. parseAnyMessage · jamesdbrock/protobuf-decoder-explainer@37bd96f · GitHub

Why was I able to do naïve recursion after the upgrade?

(That parseField function was moved to here. Did that make any difference?)

It’s hard for me to say without knowing what “the recursion wasn’t working” means. If you are referring to the error the compiler emits when it complain about an undefined references in recursive binding groups, then there is no internal change that would affect that, since it’s a local syntactic check over the binding group.

My opinion is that when you get such an error, you shouldn’t fool with manual fix points or fix. Rather you should put every binding in the recursive binding group behind defer \_ ->. The manual fix point is useful for teaching you how to manually construct such a group, but it’s completely unnecessary. Likewise, fix just introduces another name for no apparent gain, and only works for a single binding. It can reference other bindings in the group for the same reason defer can, so just use defer always.

Yeah I don’t remember why the “the recursion wasn’t working” lol.

I was hoping you were going to say something like “After the CPS refactor recursion just works because something something is lazy and…” but you didn’t.

Thanks for the advice about defer. I would like to put that advice on the parsing README as soon as I understand it well enough.

More here Help implementing a recursive Parser

Possibly relevant