logoalt Hacker News

raddan • today at 10:58 AM • 4 replies • view on HN

Combinators are functional—they always return something. But if you want to return nothing, fine; T is any type. Just return something like unit (ie, the singleton type that has nothing as a value).


Replies

rhdunn • today at 11:19 AM

There are three return states that a parser (or partial parser) can return:

1. an item (`T`) for a successful parse;

2. an error (`ParseError`) for an unrecoverable parse error;

3. a partial item (`T with ParseError`) for a recoverable parse error or warning (known statically).

You may also want to differentiate between:

1. leaf nodes (numbers, identifiers, string literals, etc.);

2. composite/nested nodes (addition, multiplication, variable assignment, etc.).

➕ show 1 reply
pyrale • today at 11:24 AM

T is not any type, T is a type defined at compile time, and usually checked against the parser’s implementation.

If you always define T as some useful stuff or unit, your experience with parser combinators and their composition is going to be miserable.

➕ show 1 reply
codebje • today at 12:07 PM

    A parser for a thing
    Is a function from a string
    To a list of pairs
    Of strings and things.
➕ show 1 reply
rdevilla • today at 11:08 AM

[dead]