Enumeration

The syntax for enumerations is not yet implemented.

type List {
	first: Any,
	rest: List
}

layout List [
	Nil = rdf:nil,
	Cons {
		first: required Any,
		rest: required List
	}
]

There must be no ambiguities between the variants of an enumeration layout.

Generated Code

Rust

Enumerations are generated as enum types in Rust:

enum Enum {
	A(A),
	B(B)
}

The actual type can be retrieved using pattern matching.

TypeScript

Enumerations are generated in multiple ways in TypeScript.

  • If no variants are storing data, an enum type is generated:

enum Enum {
  A,
  B
}
  • Otherwise, a union is generated:

type Enum = A | B;

Note that any ambiguity between A and B is detected at compile time.

Last updated