Skip to content

Add an exhaustive switch expression? #38

@lars-reimann

Description

@lars-reimann

In order to work enumerations, numbers and union types we could add an exhaustive switch expression with some predefined conditions:

Usage with an enum:

enum SomeEnum {
  A, 
  B,
}

// ...

switch {
   enumInstance is A -> { /* ... */ }
   enumInstance is B -> { /* ... */ }
}

Usage with a numbers:

switch {
  integer < 0 -> { /* ... */ }
  integer == 0 -> { /* ... */ }
  else -> { /* ... */ }
}

Usage with object:

switch {
  obj is Type1 -> { /* ... */ }
  obj is Type2 -> { /* ... */ }
  else -> { /* ... */ } // might not always be necessary if we can prove exhaustiveness
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    dsl 🗒️Issues regarding the domain specific programming language

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions