Syntax Lookup

Enter some language construct you want to know more about.
This is the switch expression keyword.

A switch expression allows you to match / destructure almost any kind of value (array, list, records, strings, numbers, variants, etc). Each branch (pattern) of a switch expression must return a value of the same type.

Example

ReScriptJS Output
type shape = Circle(float) | Square(float)

let shape = Square(3.0)

let message = switch shape {
| Circle(radius) => "Circle with radius " ++ Float.toString(radius)
| Square(length) => "Square with sides of length " ++ Float.toString(length)
}

References