Stream: ideas

Topic: Parser library with `try`


view this post on Zulip Richard Feldman (Oct 16 2024 at 14:41):

random idea: I wonder what would happen if we tried to make a parser library which defined Parser a as a type alias (for a function that returns Result) rather than an opaque type, specifically so that it could use try for chaining and early returns

view this post on Zulip Richard Feldman (Oct 16 2024 at 14:42):

maybe Parse a would be a better name in that design, since it would be a function you could just call, to "parse an a"

view this post on Zulip Richard Feldman (Oct 16 2024 at 14:43):

it's already an opaque wrapper around a function: https://github.com/lukewilliamboswell/roc-parser/blob/a0060e411db88a4f74e433f880e3f29a6bbdf8ea/package/Core.roc#L89

view this post on Zulip Richard Feldman (Oct 16 2024 at 14:43):

so basically the idea is to change := to : and then try works

view this post on Zulip Agus Zubiaga (Oct 16 2024 at 15:30):

I recently refactored roc-pg's internal decoding helpers to work like that, and I was surprised that I didn't mind threading the state explicitly.

EDIT: GitHub doesn't scroll, but the interesting file is Protocol.Backend

view this post on Zulip Agus Zubiaga (Oct 16 2024 at 15:30):

It'd be better with var and shadowing, though


Last updated: Jun 16 2026 at 16:19 UTC