Skip to content
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

Model n-ary nodes better #241

Open
dlurton opened this issue May 8, 2020 · 0 comments
Open

Model n-ary nodes better #241

dlurton opened this issue May 8, 2020 · 0 comments
Labels
good first issue Good for newcomers S Small sized task technical debt

Comments

@dlurton
Copy link
Member

dlurton commented May 8, 2020

We currently model "n-ary" nodes as direct variants of the expr sum type:

(sum expr
    // Arithmetic operators
    (plus (* expr 2))
    (minus (* expr 2))
    (times (* expr 2))
    (divide (* expr 2))
    (modulo (* expr 2))
    (string_concat (* expr 2))

    // Logical operators
    (and (* expr 2))
    (or (* expr 2))

    // Comparison operators
    (eq (* expr 2))
    (ne (* expr 2))
    (gt (* expr 2))
    (gte (* expr 2))
    (lt (* expr 2))
    (lte (* expr 2))
    (in_container (* expr 2))
    ...)

However a better method of modeling them that allows for greater re-use of Kotlin code is to model the function as another sum variant:

(sum expr
    ...
    (nary nary_op (* expr 2))
    ...)

(sum nary_op)
    // Arithmetic operators
    (plus)
    (minus)
    (times)
    (divide)
    (modulo)
    (string_concat)

    // Logical operators
    (and)
    (or)

    // Comparison operators
    (eq)
    (ne)
    (gt)
    (gte)
    (lt)
    (lte)
    (in_container)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers S Small sized task technical debt
Projects
None yet
Development

No branches or pull requests

3 participants