8000 Expose the names of generated record constructors by plt-amy · Pull Request #6975 · agda/agda · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Expose the names of generated record constructors #6975

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

Closed
wants to merge 4 commits into from

Conversation

plt-amy
Copy link
Member
@plt-amy plt-amy commented Nov 9, 2023

The keyword constructor can appear as the last token in a qualified name, as long as it's the only name part. So Foo.constructor, Foo.Bar.constructor are both valid, but constructor and Foo.constructor.bar are still syntax errors.

The Foo.constructor syntax is actual syntax. It looks like a name, but there's no constructor name in the module Foo. That would be incorrect anyway, since the record module is parametrized by a value of the record type, but the constructor isn't; see #4189. Because of this, it's not possible to control the visibility of Foo.constructor: if you want that, give the constructor an actual name.

If the constructor has a declared name, the Foo.constructor syntax is also disabled, with an error message explaining that the declared name should be used instead.

To resolve Foo.constructor, we look up Foo as an unambiguous record name, and then resolve to the actual name of the constructor, which is still kept internal. This means that Foo.constructor is in scope as long as Foo is, so this doesn't reintroduce #282. It also means that renaming the record will also "rename" the constructor, as expected.

Since we have a new name for the record, we have to make sure that the
new record is also associated with a constructor.

But we also can't associate it with the old constructor, since that
won't be applied to any parameters.

So we rename the constructor when renaming the record, and fortunately
the type checker is smart enough to recognise that it doesn't have to
come up with a *third* name for the constructor, so the parameters are
correctly instantiated.
@nad
Copy link
Contributor
nad commented Nov 10, 2023

If the constructor has a declared name, the Foo.constructor syntax is also disabled

Why? The notation record { … } is not disabled.

@plt-amy
Copy link
Member Author
plt-amy commented Nov 10, 2023

Because of the different scoping (visibility) rules. You could use Foo.constructor to get at Foo's constructor even if it's named and unexported (e.g. Foo lives in a private module which is open public hiding its constructor).

@andreasabel andreasabel added the record constructors Issues involving record constructors. label Apr 17, 2024
@andreasabel andreasabel added this to the 2.7.0 milestone Apr 17, 2024
@jespercockx
Copy link
Member

Since this is still marked as a draft, I'm moving it to later.

@jespercockx jespercockx modified the milestones: 2.7.0, later Jul 10, 2024
@andreasabel andreasabel modified the milestones: later, 2.8.0 Sep 25, 2024
@plt-amy
Copy link
Member Author
plt-amy commented Sep 25, 2024

This PR's gonna be too much of a pain to merge so I'm just gonna frankenstein a new one.

@plt-amy plt-amy closed this Sep 25, 2024
@plt-amy plt-amy deleted the aliao/issue-6964 branch September 25, 2024 15:13
@andreasabel
Copy link
Member

@andreasabel andreasabel modified the milestones: 2.8.0, never Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
record constructors Issues involving record constructors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0