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 polymorphism into the language #36

Open
denismerigoux opened this issue Dec 21, 2020 · 1 comment
Open

Add polymorphism into the language #36

denismerigoux opened this issue Dec 21, 2020 · 1 comment
Labels
🔧 compiler Issue concerns the compiler 💬 discussion Further discussion is needed ✨ enhancement New feature or request

Comments

@denismerigoux
Copy link
Contributor

The language does not have any polymorphism right now. Support for polymorphism should be added in the default calculus representation via a classic Big-Lambda type abstraction with type variables. Big lambdas should be explicitly annotated in order to avoid big-lambda inference in the type checking algorithm.

Then, the polymorphism should be reflected upwards in the intermediate representations, and reflected as minimally as possible in the surface syntax. In a first thought, surface syntax should not change at all.

@AltGr
Copy link
Collaborator

AltGr commented Jan 17, 2023

Some related remarks that will need to be considered here; on the current state of the compiler:

  • some built-in operators are polymorphic, like collection mapping or reduction. Their types are hard-coded in Shared_ast.Typing, since in fact the big-lambda can't be expressed in the general AST.
  • others are merely overloaded, and resolved early on based on the invariant that the types of their arguments must be known upon application. This works well with the "type propagation" we work with

To make the two work together, we have a slightly tricky invariant on the polymorphic operators we can accept: all the type variables in contravariant position are expected to be instanciated with concrete types when typing the arguments from right to left. Concretely, when typing map(f, x), the function argument f is typed once we know on what type it operates.

There is no contradiction with the feature proposed here, though: we will just need to be careful that we fail properly when a polymorphic operator is applied to a universally quantified type variable. The weird bit will be that our built-in collection operators are able to bypass that restriction through the trick above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 compiler Issue concerns the compiler 💬 discussion Further discussion is needed ✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants