41 lines
860 B
Plaintext
41 lines
860 B
Plaintext
// Header stays before the module.
|
|
module fmt.layout
|
|
import std.option; // explicit import
|
|
|
|
// Generic declaration.
|
|
struct Pair<T: Copy> {
|
|
first: T,
|
|
second: T,
|
|
}
|
|
|
|
enum Choice<T: Copy> {
|
|
some(T),
|
|
none
|
|
}
|
|
|
|
fn identity(x: u64) -> u64 effects [] {
|
|
x
|
|
}
|
|
|
|
fn apply<T: Copy, F: fn(T) -> T effects []>(x: T) -> T effects [] {
|
|
return F(x);
|
|
}
|
|
|
|
fn main() -> u64 effects [] {
|
|
let pair = Pair::<u64> { first: 40u64, second: 2u64 }; // keep trailing
|
|
let bytes = b"//not a comment\x00";
|
|
let x = (pair.first + pair.second) * 1u64;
|
|
if x < 43u64 {
|
|
match Choice::<u64>::some(x) {
|
|
Choice::<u64>::some(v) => {
|
|
return apply::<u64, fn identity>(v);
|
|
}
|
|
Choice::<u64>::none => {
|
|
return 0u64;
|
|
}
|
|
}
|
|
} else {
|
|
return x >> 1u64;
|
|
}
|
|
} // final
|