92c5cd59f5
- Create stdlib/Std/Io.bux with extern func declarations
- Rename C shim functions to short names (PrintLine, PrintInt, etc.)
- Update all 9 examples to use import Std::Io::{PrintLine, PrintInt};
- Remove manual extern func Std_Io_* declarations from examples
33 lines
626 B
Plaintext
33 lines
626 B
Plaintext
// Pattern Matching - Match expressions with algebraic enums
|
|
import Std::Io::{PrintLine, PrintInt};
|
|
|
|
|
|
enum Option {
|
|
Some(int),
|
|
None
|
|
}
|
|
|
|
func GetValue(opt: Option) -> int {
|
|
match opt {
|
|
Option::Some(value) => opt.data.Some_0,
|
|
Option::None => 0
|
|
}
|
|
}
|
|
|
|
func Main() -> int {
|
|
let opt1: Option = Option { tag: Option_Some };
|
|
opt1.data.Some_0 = 42;
|
|
|
|
let opt2: Option = Option { tag: Option_None };
|
|
|
|
PrintLine("opt1 value: ");
|
|
PrintInt(GetValue(opt1));
|
|
PrintLine("");
|
|
|
|
PrintLine("opt2 value: ");
|
|
PrintInt(GetValue(opt2));
|
|
PrintLine("");
|
|
|
|
return 0;
|
|
}
|