-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm.pr
58 lines (51 loc) · 1.03 KB
/
m.pr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
struct Empty {}
type Byte = u8
type IntPair = Pair(int)
type BoolPair = Pair(bool)
type IntBoolPair = DisjointPair(int, bool)
struct Pair(T) {
lhs T
rhs T
}
struct DisjointPair(Lhs, Rhs) {
lhs Lhs
rhs Rhs
}
struct LinkedList(T) {
data T
next ?*Self
}
impl LinkedList(T) {
fn init(data T) Self {
return .{
data,
next = none,
}
}
fn extend(self *Self, next_node *Self) void {
if self.next.is_none() {
self.next = some next_node
} else {
var n_node = self.next.unwrap()
n_node.extend(next_node)
}
}
}
// the entry point of the program
fn main() int {
// initialize struct and assign them to variables.
// Variables are declared with := with an optional type between : and =.
var pair = IntPair {
lhs = 1,
rhs = 2,
}
var pair2 = BoolPair {
lhs = true,
rhs = false,
}
var pair3 = IntBoolPair {
lhs = 420,
rhs = false,
}
return 0
}