Skip to content

choice — examples

← all topics · 159 examples · page 2 of 4 · raw source ↓

Runs `go` → "on"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_BoolLiteral   topic: choice   status: verified
// verified behavior: Test.go(...) == "on"

namespace Test
func label(flag: bool) -> string {
    match flag {
        true { return "on" }
        false { return "off" }
    }
}
func go() -> string { return label(true) }

Runs `go` → "sum=7"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_AsExpression   topic: choice   status: verified
// verified behavior: Test.go(...) == "sum=7"

namespace Test
choice Cmd {
    add(a: int, b: int)
    nop
}
func go() -> string {
    let c = Cmd.add(3, 4)
    return match c {
        .add(a, b) { "sum={a + b}" }
        .nop { "noop" }
    }
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_CaseViewProjection   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
choice Pair {
    one(a: int)
    two(a: int, b: int)
}
func go() -> int {
    let p = Pair.two(3, 4)
    match p {
        .one(o) { return o.a }
        .two(t) { return t.a + t.b }
    }
    return -1
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_GenericOption   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
choice Option<T> {
    some(value: T)
    none
}
func unwrapOr(o: Option<int>, fallback: int) -> int {
    match o {
        .some(v) { return v }
        .none { return fallback }
    }
    return fallback
}
func go() -> int {
    let o = Option<int>.some(99)
    return unwrapOr(o, -1)
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_GenericOption_NoneFallback   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
choice Option<T> {
    some(value: T)
    none
}
func unwrapOr(o: Option<int>, fallback: int) -> int {
    match o {
        .some(v) { return v }
        .none { return fallback }
    }
    return fallback
}
func go() -> int {
    let o = Option<int>.none()
    return unwrapOr(o, -1)
}

Runs `go` → "[3] hi"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_MultiPayloadDestructure   topic: choice   status: verified
// verified behavior: Test.go(...) == "[3] hi"

namespace Test
choice LogEntry {
    message(level: int, text: string)
    blank
}
func go() -> string {
    let e = LogEntry.message(3, "hi")
    match e {
        .message(lvl, txt) { return "[{lvl}] {txt}" }
        .blank { return "" }
    }
    return "?"
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_SinglePayloadBinding   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
choice Box {
    empty
    full(value: int)
}
func go() -> int {
    let b = Box.full(42)
    match b {
        .empty { return 0 }
        .full(v) { return v }
    }
    return -1
}

Runs `go` → "a"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Choice_ZeroPayload   topic: choice   status: verified
// verified behavior: Test.go(...) == "a"

namespace Test
choice Cmd {
    help
    quit
}
func go() -> string {
    let c = Cmd.help()
    match c {
        .help { return "a" }
        .quit { return "b" }
    }
    return "?"
}

Runs `go` → "N"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Enum_AsExpression   topic: choice   status: verified
// verified behavior: Test.go(...) == "N"

namespace Test
enum Dir { north, south }
func go() -> string {
    let d = Dir.north()
    let name = match (d: Dir) {
        .north { "N" }
        .south { "S" }
        default { "?" }
    }
    return name
}

Runs `go` → "S"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Enum_BasicDispatch   topic: choice   status: verified
// verified behavior: Test.go(...) == "S"

namespace Test
enum Direction { north, south, east, west }
func glyph(d: Direction) -> string {
    match (d: Direction) {
        .north { return "N" }
        .south { return "S" }
        .east { return "E" }
        .west { return "W" }
    }
    return "?"
}
func go() -> string { return glyph(Direction.south()) }

Runs `go` → "warn"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Enum_ExplicitValues   topic: choice   status: verified
// verified behavior: Test.go(...) == "warn"

namespace Test
enum Code { ok = 0, warn = 10, fail = 20 }
func name(c: Code) -> string {
    match (c: Code) {
        .ok { return "ok" }
        .warn { return "warn" }
        .fail { return "fail" }
        default { return "?" }
    }
}
func go() -> string { return name(Code.warn()) }

Runs `go` → "other"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Enum_WithDefaultArm   topic: choice   status: verified
// verified behavior: Test.go(...) == "other"

namespace Test
enum Size { small, medium, large }
func label(s: Size) -> string {
    match (s: Size) {
        .small { return "S" }
        default { return "other" }
    }
}
func go() -> string { return label(Size.large()) }

Runs `go` → "not found"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_IntLiteral   topic: choice   status: verified
// verified behavior: Test.go(...) == "not found"

namespace Test
func describe(code: int) -> string {
    match code {
        200 { return "ok" }
        404 { return "not found" }
        500 { return "server error" }
        default { return "unknown" }
    }
}
func go() -> string { return describe(404) }

Runs `go` → "unknown"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_IntLiteral_DefaultArm   topic: choice   status: verified
// verified behavior: Test.go(...) == "unknown"

namespace Test
func describe(code: int) -> string {
    match code {
        200 { return "ok" }
        default { return "unknown" }
    }
}
func go() -> string { return describe(301) }

Runs `go` → "neg"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_NegativeIntLiteral   topic: choice   status: verified
// verified behavior: Test.go(...) == "neg"

namespace Test
func sign(n: int) -> string {
    match n {
        -1 { return "neg" }
        0 { return "zero" }
        1 { return "pos" }
        default { return "?" }
    }
}
func go() -> string { return sign(-1) }

Runs `go` → "a-inner"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_Nested   topic: choice   status: verified
// verified behavior: Test.go(...) == "a-inner"

namespace Test
func go() -> string {
    let outer = "a"
    let inner = 1
    match outer {
        "a" {
            match inner {
                1 { return "a-inner" }
                default { return "a-other" }
            }
        }
        default { return "other" }
    }
    return "?"
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_OnLoopIndex_Categorizes   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func go() -> int {
    var evens = 0
    for i in 0..8 {
        match i % 2 {
            0 { evens += 1 }
            default { }
        }
    }
    return evens
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_RefChoice_CompositeLiteralConstruction   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
ref choice Expr {
    literal(value: int)
    add(left: Expr, right: Expr)
}
func eval(e: Expr) -> int {
    match e {
        .literal(lit) { return lit.value }
        .add(a) { return eval(a.left) + eval(a.right) }
    }
    return 0
}
func go() -> int {
    let sum = Expr_add {
        left: Expr_literal { value: 3 }
        right: Expr_literal { value: 4 }
    }
    return eval(sum)
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_RefChoice_RecursiveEval   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
ref choice Expr {
    literal(value: int)
    add(left: Expr, right: Expr)
    mul(left: Expr, right: Expr)
}
func eval(e: Expr) -> int {
    match e {
        .literal(lit) { return lit.value }
        .add(a) { return eval(a.left) + eval(a.right) }
        .mul(m) { return eval(m.left) * eval(m.right) }
    }
    return 0
}
func go() -> int {
    let tree = Expr.add(Expr.literal(2), Expr.mul(Expr.literal(3), Expr.literal(4)))
    return eval(tree)
}

Runs `go` → "admin-perms"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Match_StringLiteral   topic: choice   status: verified
// verified behavior: Test.go(...) == "admin-perms"

namespace Test
func perms(role: string) -> string {
    match role {
        "admin" { return "admin-perms" }
        "guest" { return "guest-perms" }
        default { return "none" }
    }
}
func go() -> string { return perms("admin") }

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_ControlFlow.cs::Nested_LoopWithMatchClassifier   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
func classify(n: int) -> int {
    return match n % 3 {
        0 { 0 }
        1 { 1 }
        default { 2 }
    }
}
func go() -> int {
    var twos = 0
    for i in 0..9 {
        if classify(i) == 2 { twos += 1 }
    }
    return twos
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Errors.cs::OptionInt_NoneFallsBack   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
choice OptionInt {
    some(value: int)
    none
}
func get(present: bool) -> OptionInt {
    if present { return OptionInt.some(42) }
    return OptionInt.none()
}
func go() -> int {
    let o = get(false)
    match o {
        .some(v) { return v }
        .none { return -1 }
    }
    return -1
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Errors.cs::OptionInt_SomeUnwraps   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
choice OptionInt {
    some(value: int)
    none
}
func get(present: bool) -> OptionInt {
    if present { return OptionInt.some(42) }
    return OptionInt.none()
}
func go() -> int {
    let o = get(true)
    match o {
        .some(v) { return v }
        .none { return -1 }
    }
    return -1
}

Runs `go` → "notFound"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Errors.cs::Result_ChoiceErrorVariant   topic: choice   status: verified
// verified behavior: Test.go(...) == "notFound"

namespace Test
choice DbError {
    notFound
    timeout
    connectionFailed(message: string)
}
func lookup(id: int) -> Result<int, DbError> {
    if id == 0 { return error(DbError.notFound()) }
    return ok(id)
}
func go() -> string {
    let r = lookup(0)
    if r.IsError {
        match r.Error {
            .notFound { return "notFound" }
            .timeout { return "timeout" }
            .connectionFailed(c) { return "conn" }
        }
    }
    return "ok"
}

Runs `go` → "conn:down"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Errors.cs::Result_ChoiceErrorWithPayload   topic: choice   status: verified
// verified behavior: Test.go(...) == "conn:down"

namespace Test
choice DbError {
    notFound
    connectionFailed(message: string)
}
func lookup(id: int) -> Result<int, DbError> {
    return error(DbError.connectionFailed("down"))
}
func go() -> string {
    let r = lookup(1)
    if r.IsError {
        match r.Error {
            .notFound { return "notFound" }
            .connectionFailed(c) { return "conn:{c.message}" }
        }
    }
    return "ok"
}

Runs `go` → "notFound"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Errors.cs::Result_DotCaseShorthandError   topic: choice   status: verified
// verified behavior: Test.go(...) == "notFound"

namespace Test
choice DbError {
    notFound
    timeout
}
func lookup(id: int) -> Result<int, DbError> {
    if id == 0 { return error(.notFound) }
    return ok(id)
}
func go() -> string {
    let r = lookup(0)
    if r.IsError {
        match r.Error {
            .notFound { return "notFound" }
            .timeout { return "timeout" }
        }
    }
    return "ok"
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Misc.cs::Enum_MatchWithDefault   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
enum Dir { north, south, east, west }
func go() -> int {
    let d = Dir.north()
    match (d: Dir) {
        .north { return 1 }
        default { return 0 }
    }
    return -1
}

Runs `go` → "active"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Integration.cs::CrossNamespace_ChoiceConstructedAndMatched   topic: choice   status: verified
// verified behavior: Test.go(...) == "active"

namespace Model

choice Status {
    active
    suspended(reason: string)
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Interpolation.cs::InterpolationInsideMatchArm   topic: choice   status: verified
// compiles cleanly (no auto-run claim was extracted)

func go() -> string {
  let n = 2
  return match n {
    1 { "one:1" }
    2 { "two:{n}" }
    default { "x" }
  }
}

Runs `test` → "busy"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Choice_Bare_Variants_Tag_Discrimination_Pin   topic: choice   status: verified
// verified behavior: Test.test(...) == "busy"

namespace Test

choice Status {
    idle
    busy
    done
}

func describe(s: Status) -> string {
    match (s: Status) {
        .idle { return "idle" }
        .busy { return "busy" }
        .done { return "done" }
        default { return "unknown" }
    }
    return "unknown"
}

func test() -> string {
    return describe(Status.busy())
}

Runs `test` → "west"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Choice_Many_Bare_Variants_Pin   topic: choice   status: verified
// verified behavior: Test.test(...) == "west"

namespace Test

choice Direction {
    north
    south
    east
    west
}

func opposite(d: Direction) -> string {
    match (d: Direction) {
        .north { return "south" }
        .south { return "north" }
        .east { return "west" }
        .west { return "east" }
        default { return "?" }
    }
    return "?"
}

func test() -> string {
    return opposite(Direction.east())
}

Runs `test` → "H"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Enum_ExplicitValues_MatchExpression   topic: choice   status: verified
// verified behavior: Test.test(...) == "H"

namespace Test

enum Priority {
    low = 1
    medium = 5
    high = 10
}

func label(p: Priority) -> string {
    match (p: Priority) {
        .low { return "L" }
        .medium { return "M" }
        .high { return "H" }
        default { return "?" }
    }
}

func test() -> string {
    return label(Priority.high())
}

Runs `test` → "g"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Enum_Match_BasicDispatch   topic: choice   status: verified
// verified behavior: Test.test(...) == "g"

namespace Test

enum Color {
    red
    green
    blue
}

func describe(c: Color) -> string {
    match (c: Color) {
        .red { return "r" }
        .green { return "g" }
        .blue { return "b" }
        default { return "?" }
    }
}

func test() -> string {
    return describe(Color.green())
}

Runs `test` → "warn"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Enum_Match_ExplicitValues_Dispatch   topic: choice   status: verified
// verified behavior: Test.test(...) == "warn"

namespace Test

enum Code {
    ok = 0
    warn = 10
    fail = 20
}

func name(c: Code) -> string {
    match (c: Code) {
        .ok { return "ok" }
        .warn { return "warn" }
        .fail { return "fail" }
        default { return "?" }
    }
}

func test() -> string {
    return name(Code.warn())
}

ILEmitterTests2__Enum_Match_WithDefault

choice runnable verified

Runs `test` → "other"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Enum_Match_WithDefault   topic: choice   status: verified
// verified behavior: Test.test(...) == "other"

namespace Test

enum Size {
    small
    medium
    large
}

func label(s: Size) -> string {
    match (s: Size) {
        .small { return "S" }
        default { return "other" }
    }
}

func test() -> string {
    return label(Size.large())
}

Runs `test` → "S"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Enum_StoredInLocal_ThenPassedToFunc   topic: choice   status: verified
// verified behavior: Test.test(...) == "S"

namespace Test

enum Dir {
    north
    south
}

func label(d: Dir) -> string {
    match (d: Dir) {
        .north { return "N" }
        .south { return "S" }
        default { return "?" }
    }
}

func test() -> string {
    let d = Dir.south()
    return label(d)
}

ILEmitterTests2__Literal_Match_Bool

choice runnable verified

Runs `test` → "no"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Literal_Match_Bool   topic: choice   status: verified
// verified behavior: Test.test(...) == "no"

namespace Test

func label(b: bool) -> string {
    match b {
        true { return "yes" }
        false { return "no" }
        default { return "?" }
    }
}

func test() -> string {
    return label(false)
}

ILEmitterTests2__Literal_Match_Int

choice runnable verified

Runs `test` → "two"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Literal_Match_Int   topic: choice   status: verified
// verified behavior: Test.test(...) == "two"

namespace Test

func describe(n: int) -> string {
    match n {
        1 { return "one" }
        2 { return "two" }
        3 { return "three" }
        default { return "other" }
    }
}

func test() -> string {
    return describe(2)
}

Runs `test` → "other"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Literal_Match_Int_Default   topic: choice   status: verified
// verified behavior: Test.test(...) == "other"

namespace Test

func describe(n: int) -> string {
    match n {
        1 { return "one" }
        default { return "other" }
    }
}

func test() -> string {
    return describe(99)
}

Runs `test` → "neg"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Literal_Match_NegativeInt   topic: choice   status: verified
// verified behavior: Test.test(...) == "neg"

namespace Test

func sign(n: int) -> string {
    match n {
        -1 { return "neg" }
        0 { return "zero" }
        1 { return "pos" }
        default { return "other" }
    }
}

func test() -> string {
    return sign(-1)
}

ILEmitterTests2__Literal_Match_String

choice runnable verified

Runs `test` → "hola"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Literal_Match_String   topic: choice   status: verified
// verified behavior: Test.test(...) == "hola"

namespace Test

func greet(lang: string) -> string {
    match lang {
        "en" { return "hello" }
        "es" { return "hola" }
        "fr" { return "bonjour" }
        default { return "hi" }
    }
}

func test() -> string {
    return greet("es")
}

ILEmitterTests2__Match_Expression_Choice

choice runnable verified

Runs `test` → 42

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_Choice   topic: choice   status: verified
// verified behavior: Test.test(...) == 42

namespace Test

choice Option {
    some(value: int)
    none
}

func unwrap(o: Option) -> int {
    let v = match o {
        .some(x) { x }
        .none { 0 }
    }
    return v
}

func test() -> int {
    return unwrap(Option.some(42))
}

Runs `test` → "ok"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_ChoiceString   topic: choice   status: verified
// verified behavior: Test.test(...) == "ok"

namespace Test

choice Result {
    ok(value: int)
    err(message: string)
}

func unwrap(r: Result) -> string = match r {
    .ok(v) { "ok" }
    .err(msg) { "err" }
    default { "?" }
}

func test() -> string {
    return unwrap(Result.ok(42))
}

ILEmitterTests2__Match_Expression_Enum

choice runnable verified

Runs `test` → "N"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_Enum   topic: choice   status: verified
// verified behavior: Test.test(...) == "N"

namespace Test

enum Dir {
    north
    south
}

func test() -> string {
    let d = Dir.north()
    let name = match (d: Dir) {
        .north { "N" }
        .south { "S" }
        default { "?" }
    }
    return name
}

Runs `test` → "two"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_ExpressionBody   topic: choice   status: verified
// verified behavior: Test.test(...) == "two"

namespace Test

func label(n: int) -> string = match n {
    1 { "one" }
    2 { "two" }
    default { "?" }
}

func test() -> string {
    return label(2)
}

Runs `test` → "seven"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_InlineLetAssignment   topic: choice   status: verified
// verified behavior: Test.test(...) == "seven"

namespace Test

func test() -> string {
    let x = 7
    let tag = match x {
        1 { "one" }
        7 { "seven" }
        default { "other" }
    }
    return tag
}

Runs `test` → "two"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_IntLiteral   topic: choice   status: verified
// verified behavior: Test.test(...) == "two"

namespace Test

func test() -> string {
    let x = match 2 {
        1 { "one" }
        2 { "two" }
        default { "other" }
    }
    return x
}

Runs `test` → "neg"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_NegativeLiteral   topic: choice   status: verified
// verified behavior: Test.test(...) == "neg"

namespace Test

func sign(n: int) -> string = match n {
    -1 { "neg" }
    0 { "zero" }
    1 { "pos" }
    default { "other" }
}

func test() -> string {
    return sign(-1)
}

Runs `test` → "hola"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_Expression_StringLiteral   topic: choice   status: verified
// verified behavior: Test.test(...) == "hola"

namespace Test

func greet(lang: string) -> string = match lang {
    "en" { "hello" }
    "es" { "hola" }
    default { "hi" }
}

func test() -> string {
    return greet("es")
}

Runs `test` → "level: medium"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests2.cs::Match_ExpressionBody_ResultInInterpolation   topic: choice   status: verified
// verified behavior: Test.test(...) == "level: medium"

namespace Test

func levelName(n: int) -> string = match n {
    1 { "low" }
    2 { "medium" }
    default { "?" }
}

func test() -> string {
    let name = levelName(2)
    return "level: {name}"
}