-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix/adts #869
Merged
Merged
Fix/adts #869
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit refactors the desugaring step of ADTs. Additionally, it makes `data` a reserved keyword and makes the parentheses after a `case` declaration optional.
Also improve parsing so that blocked definitions of ADTs don't abort too early
Also fix a bug where methods in ADT cases weren't being desugared!
Before this commit, putting an ADT in, e.g., a tuple would disallow matching on it (with a compiler crash as the result).
Now there is a warning whenever a variable overlaps with an ADT case.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes some of the issues with the recent effort to add
abstract data types to Encore. The changes are a combination of
refactoring, bug fixes and feature additions. I have a few ideas
for other features we should support, but this PR should make ADTs
"stable enough" to be used.
I will write upI have written an RFC about futurework. Excluding things like refactoring and improved errors for
parsing and typechecking, at least the following changes have been
made:
data
is a reserved keyword (which required parts of thestandard library to be rewritten, meaning this is a breaking
change).
A
case
declaration can only be given a single type, and not,e.g. a composite capability.
When a
case
has no fields, parentheses are optional:This has the drawback that using a field-less constructor has a
different syntax, since parentheses are required there:
This is currently addressed by emitting a warning whenever a
variable has the same name as an existing ADT case (e.g. on
lines 2 and 4 above). In the future, I think parentheses should
be optional in these cases as well.
A
case
declaration must now use have a type declared usingdata
(and not a class or trait).A
case
declaration can now override the methods declared intheir corresponding
data
declaration. See testadt/expr.enc
ADT values can now be nested in non-ADT structures, e.g. tuples
and
Maybe
s, and vice versa. See testadt/nestedMatch.enc
.The contents of a polymorphic ADT can be extracted with a
match
. See testadt/polyAdt.enc
.Note that, with the exception of the added tests, this PR removes
more lines than it adds.