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

Add tuples to the surface language, allow tuples for argument passing #554

Merged
merged 8 commits into from
Jan 8, 2024

Conversation

AltGr
Copy link
Contributor

@AltGr AltGr commented Dec 19, 2023

Upon adding tuples to the surface language, we wanted to ensure that, at least
on surface, there was no difference between applying a function to a pair or to
two arguments.

Technically, defining a function of a pair is forbidden (and not syntactically
possible), and during conversion to scopelang, we process with de-tuplification of
function arguments when needed. This transformation is based on typing
information that is of the same kind as what is used for overload resolution.

Towards this purpose, explicit types have been added to application nodes in the
AST ; besides and for convenience, the application of operators is split into a
different EAppOp node, replacing the plain EOp node.

No helpers to destruct them at the moment
As part of making tuples first-class citizens, expliciting the arity upon
function application was needed (so that a function of two args can
transparently -- in the surface language -- be applied to either two arguments
or a pair).

It was decided to actually explicit the whole type of arguments because the cost
is the same, and this is consistent with lambda definitions.

A related change done here is the replacement of the `EOp` node for operators by
an "operator application" `EAppOp` node, enforcing a pervasive invariant that
operators are always directly applied. This makes matches terser, and highlights
the fact that the treatment of operator application is almost always different
from function application in practice.
Copy link
Contributor

@denismerigoux denismerigoux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @AltGr! As always, a few benign remarks before merging but this is excellent work.

compiler/desugared/from_surface.ml Outdated Show resolved Hide resolved
compiler/desugared/from_surface.ml Outdated Show resolved Hide resolved
compiler/lcalc/compile_without_exceptions.ml Show resolved Hide resolved
compiler/lcalc/from_dcalc.ml Show resolved Hide resolved
compiler/scopelang/from_desugared.ml Show resolved Hide resolved
compiler/shared_ast/print.mli Show resolved Hide resolved
compiler/shared_ast/typing.mli Show resolved Hide resolved
compiler/surface/ast.ml Show resolved Hide resolved
tests/test_func/bad/bad_func.catala_en Outdated Show resolved Hide resolved
tests/test_tuples/good/tuples.catala_en Show resolved Hide resolved
@AltGr AltGr merged commit 6855870 into CatalaLang:master Jan 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants