-
Notifications
You must be signed in to change notification settings - Fork 97
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
Design for polymorphic IDL types #611
Conversation
@@ -117,6 +117,34 @@ In addition to this basic grammar, a few syntactic shorthands are supported that | |||
| <name> := <name> : null (only in variants) | |||
``` | |||
|
|||
We also support polymorphic type definitions as syntactic shorthands that will be compiled to the basic forms: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about it, maybe we should just support polymorphism in the core grammar, instead of syntactic shorthands. It's up to the codegen for the target language to decide if they want to do monomorphization. If the target language supports polymorphism, the generated binding will be more readable this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that easy. If you wanted to enable dispatching to monomorphised definitions on the callee end then you'd need to provide type information to do that with (the values are not generally enough). So we'd need to do type passing as evidence, and ways to construct/destruct that, which adds a whole layer of complexity (plus enables polymorphism to become non-parametric, which may be undesirable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks okay as far as syntax goes, but it doesn't fully define semantics. Type constructors introduce extra complexity regarding recursion, since you must ensure that their expansion always terminates. One way to enforce that is by requiring that all recursion is uniform, but that is a somewhat non-trivial check (which is the reason why we haven't even implemented that check in AS yet :) ).
So I'm somewhat hesitant to spend time on this right now, and would rather suggest deferring it until after devnet launch. WDYT?
@@ -117,6 +117,34 @@ In addition to this basic grammar, a few syntactic shorthands are supported that | |||
| <name> := <name> : null (only in variants) | |||
``` | |||
|
|||
We also support polymorphic type definitions as syntactic shorthands that will be compiled to the basic forms: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that easy. If you wanted to enable dispatching to monomorphised definitions on the callee end then you'd need to provide type information to do that with (the values are not generally enough). So we'd need to do type passing as evidence, and ways to construct/destruct that, which adds a whole layer of complexity (plus enables polymorphism to become non-parametric, which may be undesirable).
<typ-args> ::= < <typ>,* > | ||
``` | ||
|
||
Polymorphism is only allowed in the type definitions. `<reftype>` and `<actor>` are always monomorphic. Type definitions are duplicated (monomorphized) to the basic forms according to the different instantiations of `<typ-args>`. For example, the following code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be precise, this isn't polymorphism (type lambdas on the term level), it's type constructors (lambdas on the type level). So I would avoid talking about polymoprhism and monomorphisation. Better call it parameterised type definitions that get expanded.
Shall we close this until we know we want to go there? |
Sure, let's close this. Even Rust doesn't need IDL support for polymorphism, so we are good. |
## Changelog for motoko-base: Branch: next-moc Commits: [dfinity/motoko-base@520ccf5d...712d0587](dfinity/motoko-base@520ccf5...712d058) * [`cba05e81`](dfinity/motoko-base@cba05e8) Publish on Mops ([dfinity/motoko-base#618](https://togithub.com/dfinity/motoko-base/issues/618)) * [`d81f5527`](dfinity/motoko-base@d81f552) Add commit hash to `matchers` dependency ([dfinity/motoko-base#621](https://togithub.com/dfinity/motoko-base/issues/621)) * [`c86d76ff`](dfinity/motoko-base@c86d76f) doc: update `List.mo` ([dfinity/motoko-base#616](https://togithub.com/dfinity/motoko-base/issues/616)) * [`4c2a90e7`](dfinity/motoko-base@4c2a90e) Fix compiler warning in `Array.take()` method ([dfinity/motoko-base#611](https://togithub.com/dfinity/motoko-base/issues/611))
## Changelog for motoko-base: Branch: next-moc Commits: [dfinity/motoko-base@520ccf5d...712d0587](dfinity/motoko-base@520ccf5...712d058) * [`cba05e81`](dfinity/motoko-base@cba05e8) Publish on Mops ([dfinity/motoko-base#618](https://togithub.com/dfinity/motoko-base/issues/618)) * [`d81f5527`](dfinity/motoko-base@d81f552) Add commit hash to `matchers` dependency ([dfinity/motoko-base#621](https://togithub.com/dfinity/motoko-base/issues/621)) * [`c86d76ff`](dfinity/motoko-base@c86d76f) doc: update `List.mo` ([dfinity/motoko-base#616](https://togithub.com/dfinity/motoko-base/issues/616)) * [`4c2a90e7`](dfinity/motoko-base@4c2a90e) Fix compiler warning in `Array.take()` method ([dfinity/motoko-base#611](https://togithub.com/dfinity/motoko-base/issues/611))
No description provided.