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

Allow sum types' subtypes to be used as their own types #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TheLimePixel
Copy link
Owner

@TheLimePixel TheLimePixel commented Mar 30, 2024

Motivation

Over the years, due to develpers' frustration with the enum types in languages such as Rust and Swift, where enum variants cannot be used as their own types, several solutions have been proposed to fix this and with that remove some unnecessary code duplication. One of the proposals which has perhaps garnered the most notoriety is the following Rust proposal. Ultimately, it was rejected due to being a quite a hefty change to the existing language, which could bring unforseen consequences.

Bento, on the other hand, is far from finished and as such I have mae the following PR to incorporate the above proposal together with a few quality-of-life features into the language.

Changes

  • sum types' subtypes can now be used as their own types
  • subtype constructor still create objects of sum types unless otherwise specified
  • objects of subtypes can be imlicily coersed into objects of their supertypes
  • the ~ and ^ prefix operators have been added to explicitly do the above conversions much more succinctly
  • the scope operator can now be implicitly used for members of the expected type
  • let now needs to be used when matching to allow the above feature
  • arrows are now used in matching to allow specifying a type after let
  • a branch in an if-match can now have multiple possible patterns
  • if-matching can now also be used for matching by equality
  • ... has been added as a valid pattern within destructuring patterns

@TheLimePixel TheLimePixel changed the title Treat sum types as named closed unions of other types Allow sum types' subtypes to be used as their own types Apr 12, 2024
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.

1 participant