Skip to content
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 16 commits into from
Feb 6, 2019
Merged

Fix/adts #869

merged 16 commits into from
Feb 6, 2019

Conversation

EliasC
Copy link
Contributor

@EliasC EliasC commented Jul 24, 2018

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 up I have written an RFC about future
work. 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 the
    standard 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:

    data Option
    case Some(x : int) : Option
    case None : Option
    

    This has the drawback that using a field-less constructor has a
    different syntax, since parentheses are required there:

    val n1 = None() : Option
    val n2 = None : Unit -> Option
    match Some(42) with
      case None => println("This is actually a catch all!")
      case Some(x) => println("This will not be run")
    end
    

    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 using
    data (and not a class or trait).

  • A case declaration can now override the methods declared in
    their corresponding data declaration. See test adt/expr.enc

  • ADT values can now be nested in non-ADT structures, e.g. tuples
    and Maybes, and vice versa. See test adt/nestedMatch.enc.

  • The contents of a polymorphic ADT can be extracted with a
    match. See test adt/polyAdt.enc.

Note that, with the exception of the added tests, this PR removes
more lines than it adds.

EliasC added 15 commits July 18, 2018 09:56
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.
@EliasC EliasC changed the title Fix/ad ts Fix/adts Jul 24, 2018
@EliasC EliasC mentioned this pull request Jul 24, 2018
@kikofernandez kikofernandez merged commit 3d5e973 into parapluu:development Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants