The MLscript programming language. Functional and object-oriented; structurally typed and sound; with powerful type inference. Soon to have full interop with TypeScript!
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.)
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.
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'senum
classes.)