3 ms·
Look for languages with dependent typing. Idris and Liquid Haskell are the two that spring to my mind. Other than that, TypeScript has decent support for the c
by chrismorgan 8y ago
Look for languages with dependent typing. Idris and Liquid Haskell are the two that spring to my mind.
Other than that, TypeScript has decent support for the concept, though with standalone functions rather than methods: you’d define your “variants” as types (or interfaces), define the “enum” as the union of those types (e.g. `Foo | Bar`), and then have your functions take either the entire “enum” type, or specific “variant” types. In place of Rust’s `match`, you will then use type guards to narrow the “enum” type down to one (or more, if you like) of the “variant” types. See https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types https://www.typescriptlang.org/docs/handbook/advanced-types.... for a bit of info.