plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
examples/match.plum
| 0e1801a | 1 | enum Color = |
| 0e1801a | 2 | | Red |
| 0e1801a | 3 | | Green |
| 0e1801a | 4 | | Blue |
| 0e1801a | 5 | |
| 0e1801a | 6 | enum Option = |
| 0bb6882 | 7 | | Some[Int] |
| 0e1801a | 8 | | None |
| 0e1801a | 9 | |
| 0fe3528 | 10 | fun describeNumber(n: Int) -> Str = |
| 0e1801a | 11 | match n |
| 0e1801a | 12 | 0 => |
| 87b54a9 | 13 | "zero" |
| 0e1801a | 14 | 1 => |
| 87b54a9 | 15 | "one" |
| 0e1801a | 16 | _ => |
| 87b54a9 | 17 | "many" |
| 0e1801a | 18 | |
| 0fe3528 | 19 | fun describeBool(b: Bool) -> Int = |
| 0e1801a | 20 | match b |
| 0e1801a | 21 | True => |
| 87b54a9 | 22 | 1 |
| 0e1801a | 23 | False => |
| 87b54a9 | 24 | 0 |
| 0e1801a | 25 | |
| 0fe3528 | 26 | fun bindExample(n: Int) -> Int = |
| 0e1801a | 27 | match n |
| 0e1801a | 28 | x => |
| 87b54a9 | 29 | x |
| 0e1801a | 30 | |
| 0fe3528 | 31 | fun describeColor(c: Color) -> Str = |
| 0e1801a | 32 | match c |
| 0e1801a | 33 | Red => |
| 87b54a9 | 34 | "red" |
| 0e1801a | 35 | Green => |
| 87b54a9 | 36 | "green" |
| 0e1801a | 37 | Blue => |
| 87b54a9 | 38 | "blue" |
| 0e1801a | 39 | |
| 0fe3528 | 40 | fun describeOption(opt: Option) -> Int = |
| 0e1801a | 41 | match opt |
| 0e1801a | 42 | Some(v) => |
| 87b54a9 | 43 | v |
| 0e1801a | 44 | None => |
| 87b54a9 | 45 | 0 |
| fe36a46 | 46 | |
| 0fe3528 | 47 | fun main() -> Int = |
| fe36a46 | 48 | describeOption(Some(5)) |