Skip to main content
Version: 1.0.0

Enumerations

An enumeration defines a closed set of named values: ticket priority, case status or verification outcome. It keeps these choices distinct from free text.

Declare and use a business choice​

priorities.tb
module examples.priorities

enum Priority
normal
watch
urgent

function Classify
takes overdue_days as Int
gives Priority
do
if overdue_days >= 7
give Priority.urgent
else if overdue_days >= 3
give Priority.watch
else
give Priority.normal

Priority.urgent is a value of Priority, not Text. Another enumeration may declare an urgent member without becoming interchangeable: type identity matters, not just the member name.

At program boundaries​

In a typed JSON argument or result, this member is represented as "urgent". The runtime validates it against the expected enumeration. "critical" is rejected if that member was not declared. Handler and provider responses remain subject to this check.

The == and != comparisons require values of the same enum type. Enum types can be imported and used inside records, lists and optionals.

Choose the right type​

  • Use an enum for a closed vocabulary reviewed with the program.
  • Use Text for free-form content such as the ticket message.
  • Use Optional of Priority when priority may genuinely be absent, instead of an artificial member that mixes absence with a business decision.

text(Priority.urgent) returns "urgent", the member's canonical name. Imported enums work the same way. Lists and optionals are not implicitly converted; unwrap an optional explicitly first. For translated display labels, write a pure function mapping members to the required business text.

Continue​

Exhaustive selection​

match selects one branch by nominal enum value. Every member must appear exactly once. Adding an enum member therefore reports selections that need updating, including in importing modules.

labels.tb
module examples.labels

enum Priority
normal
urgent

function Label
takes priority as Priority
gives Text
do
match priority
case Priority.normal
give "Normal"
case Priority.urgent
give "Urgent"

The value is evaluated once and branch bindings remain local. Calls, human pauses and limits keep their usual controls. There is no default case or implicit conversion from text to enum. Use if for numeric or open conditions.