Skip to content

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.

2 participants