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
Namespace-qualified imports #340
Conversation
A few comments:
|
Thank you for the review @jvanbruegge
We could introduce Mentioned it in "Alternatives".
Good point, I did not realize that. However, I can't come up with an example where that would be important, so I'm not too worried about it. Mentioned it in "Unresolved Questions".
I guess it won't hurt to add this. Added.
I now realize I forgot to include the rules in Proposed Change Specification (fixed). The desugaring does not depend on imports per se – it depends on the namespace from which For tuples, it's quite intuitive. Both imports and
I included a requirement in the specification that demands helpful error messages in this case. |
6479073
to
da0949c
Compare
I thought more about having
It probably is if you take a look at explicit imports. At the moment you can do |
Yes, true. I'll try to think of a way to address these issues. |
@jvanbruegge I addressed both issues.
|
Yes, the changes look really good and I don't have any further comments 👍 |
I changed |
I like the proposal, but I find the use of a pair to refer to the term-level/type-level namespaces a bit strange. How about using
For exports:
|
@sheaf There are definitely advantages to the But the Especially I don't think that splitting a single import into three lines is a good idea, at least based on my experience. Imports already can be a sizable part of a module. Here's a tool I recently wrote: https://github.com/serokell/hackage-search/blob/fa02183c88cb8fe58da65456d9b774395a5f40ff/backend/Download.hs Its import section looks like this:
Now, say I want to use namespace-specific aliases in those imports. That's what I get with the currently proposed syntax:
Not a huge difference. But here's the version with
Individually, each import is more readable, but collectively, it ends up less readable (in my opinion) due to excessive repetition. What about
To me, it looks like keyword soup, i.e. not an improvement over Anyway, that's just my perspective. I'll mention the |
I don't see advantages of this proposal over the relevant parts of #270. I personally find the I also was hoping that this counterproposal to #270 would aim to be lighter -- but it's not. It's about the same weight (to me). A concrete downside of this proposal is that is makes module dependency checking harder: The notion of I think what we may need here is to reorganize the soup that has been made of this proposal, #214, and #270. These proposals are all trying to solve the same problem, but they have different moving pieces. Critically, there is some degree of flexibility of which pieces we use. For example, the |
It is basically a subset of #270, but the motivation mentions neither punning nor future features, as @simonpj suggested. The syntax is different, but I currently believe it's better, after the case study I did in #340 (comment) In actual programs I expect it to result in better readability.
To the contrary, I attempted to include most of the same changes but with a different motivation. The one thing left is
I can't really imagine how that document would look like, but if someone was to write it, they can go ahead and copy parts of my text without attribution. I just put it out there to motivate a subset of #270, and tried to improve minor technicalities while I was at it. |
Yes, that's the way I understand it. It let's us focus on a single question (how to disambiguate ambiguous references), independent of other concerns. I like that. There are three bits here:
Personally I quite like (1) as an alternative to #214. We can argue about (3). But I cordially dislike (2) -- it's at the root of @rae's objection above. I'm not sure it's essential to the proposal. |
At the root of (2) is the following question. If a module M exports both a type X and a term X (regardless of whether or not they are related) , how can we selectively import one but not the other:
In the body of the module we can use qualified names, by going
and now using
That looks plausible doesn't it? |
This reminds me of the arguments for having a separate Before, it was hard to notify the motivate, but I think this proposal provides some motivation because: import qualified Data.Proxy as (_, T)
open T allows restoring the property that |
I really like the distinction between Import and open. This suggested "open" reminds me of "with" in nix or, a better match, "using" in Rust. Splitting import and open would also play reasonable together with qualified import as default. |
#321 is a funny little proposal of mine I don't expect to be wildly popular, but it turns out the Just a small bit of extra motivation----I just hope it doesn't backfire with anyone that thinks #321 is frivolous getting a distaste for this! |
Concerning proposed change 4.): Is
equivalent to
? Concerning 7.): |
This proposal introduces a uniform way to specify the namespace (type or data) from whence a name comes. It does so by reusing an existing mechanism: module qualification.
The main idea is to allow compound aliases in imports:
In a compound alias, the first component qualifies the data namespace, and the second component qualifies the type namespace.
Rendered