## Features Rust-like borrow checker: - Variables are moved by default ``` let a = 5 let b = a print(a) // Error: 'a' has been moved -> b = a ``` - Anonymous union type ``` let a: int | str = 5 if a is int { print("a is an integer") // Here 'a' is treated as int } else { print("a is a string") // Here 'a' is treated as str } match a { int => print(a), // Here 'a' is treated as int str => print(a), // Here 'a' is treated as str } ``` - Named union ``` enum Colors { Red, Blue, Green, } let color = Colors::Red if color is Colors::Blue { ... } else if color is Colors::Red { ... } else { ... } ``` - Named union with associated value ``` enum Colors { Red: (int, int, int), Green: (int, int, int), Blue: (int, int, int), } let color = Colors::Blue(0, 0, 255) match color { Colors::Blue => ... // color is treated as an (int, int, int) tuple } ``` If all associated values are of the same type, it can be written this way ``` enum Colors: (int, int, int) { Red, Blue, Orange } ``` Associated values can be assigned as constants ``` enum Colors { Red = (255, 0, 0), Green = (0, 255, 0), Blue = (0, 0, 255), } let color = Colors::Red print(color) // Colors::Red(255, 0, 0) ``` ## Functions Like Haskell, but with optional brackets. Also, there is optional typing before the function definition, and optional argument naming. factorial :: Int -> Int :: num factorial 0 = 1 factorial n = n * factorial (n - 1) factorial n = { ret acc = 1; for n in 0..n { acc *= n; } } > A variable marked with `ret` will be returned when the function ends. mut acc = 55 // mutable let acc = 65 // immutable ret acc = 88 // mutable and will be returned ## AST // Statements return None Expression { } Program - Statement - Let - Name: "..." - Type?: Type::... - Value: Expression::... - Expr - Literal - String: "Hello!"