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

Add enumerated types (not ADTs) #158

Open
LPTK opened this issue Mar 15, 2023 · 0 comments
Open

Add enumerated types (not ADTs) #158

LPTK opened this issue Mar 15, 2023 · 0 comments
Labels

Comments

@LPTK
Copy link
Contributor

LPTK commented Mar 15, 2023

The original idea of enumerated types is to name some constants of an underlying type and treat these as cases of a new nominal type.

enum Status: Int {
  On = 1
  Off = 0
}
let x: Status = Status.On
let y: Status = 0 // error
x + 1 // allowed because the `: Int` annotation publicizes the relationship

We could also generalize this so that constructors can not range over single values but whole sets of values, possibly filtered by a predicate (for when we have logical refinement types).

(This is different from the way recent languages use enum to define brand new nominal ADTs, which seems like a misappropriation of the original concept/name, probably from the original sin of Java's enum classes.)

@LPTK LPTK added the feature label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant