# Enums, payloads, and match

enum names a closed set of cases. Payload cases can carry one typed value, and match selects a branch with an optional binding.

Last updated: 2026-09-09

Package: language | Status: experimental

Tags: cpu, else, enum, language, logic, match, with, yeho

Use an enum when the valid states are finite and you want the compiler and reader to see every named possibility.

```yh
enum Name { Case, Payload(Type value) }
match value { Case { ... } Payload with name { ... } else { ... } }
```


## Complete program

Bind the explanation carried by a failed result and display it.

Verification: type checked

```yh
enum Result
{
    Ready,
    Failed(text reason)
}
Result result = Result.Failed("The player name is missing")
match result
{
    Result.Ready { Console.Log("Ready") }
    Result.Failed with reason { Console.Log(reason) }
    else { Console.Log("Unknown result") }
}

```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.language__enums_match"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/language--enums-match/complete --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


Plain enums are stable enough for ordinary use; richer payload matching remains experimental across targets.

The removed choice spelling is not accepted. Use enum.

Source: yeho/parser_declarations.cpp parseEnumDecl; parser_statements.cpp parseMatchStatement; conformance payload-enum-patterns

AI training permission: https://demonhunterlabs.com/ai-use
