-
Notifications
You must be signed in to change notification settings - Fork 107
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
Allow explicit imports #2354
Comments
Would that be hard to add, @crusso? Would this make sense as a orthogonal feature?
Again, if we add |
Yes, I think this might be doable, hopefully just by extending object patterns and allowing imports with non-trivial patterns. Not sure how type field patterns would look for synthesized (not checked) patterns though - I guess you'd just have to provide the type definition. The other question is whether you should be allowed to refer to the type identifier within the enclosing pattern, or just in continuation of the let. I also worry that our super-liberal recursion might pose problems here. |
Can’t you always desugar (conceptually) object patterns into accessors? If so, then hopefully there are no (conceptual) problems with recursive typing. But only trying it will tell… |
@crusso, I think it's inevitable that type fields are not allowed in synthesis patterns. But the only place with synthesis patterns are functions parameters, where they do not seem particularly useful anyway. @nomeata, desugaring only works for patterns in analysis position, but those are unproblematic anyway. It's the synthesis case that we cannot handle. Consider:
|
Is that different from the following?
|
EDIT: please ignore most of what follows. #3076 implements specific imports and the pattern syntax Wouldn't this be an instance of an Just spotted #2354 (comment) above, we seem to be in agreement! @nomeata import { type Result; mkErr = fooErr } "Result"; would import |
…ield import (#3076) Resolves #2354, the bulk of it. We can now import subsets of modules: ``` Motoko import { cons; nil = empty } = "lib/ListM"; let s = cons(1, empty()); ``` Yay! These will be done separately: - importing of `type` fields explicitly, - dealing with explicit imports in the `languageServer` (#3078).
Story
As a developer, I want to be able to explicitly import unqualified types and functions from other modules.
Motivation
Currently we can only import modules as a whole with a qualified identifier.
This leads to a lot of
Result.Result
which looks silly, and makes people create module local private aliases.This is bad because:
Demo
I want something like this to compile
Design
This doesn't just work if we allow object patterns, because we can't project type components that way.
It might also be nice to have a more compact format for the "import both as qualified and explicit" pattern, as shown above.
The text was updated successfully, but these errors were encountered: