-
Notifications
You must be signed in to change notification settings - Fork 0
/
core-overloads.boba
147 lines (111 loc) · 3.07 KB
/
core-overloads.boba
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { * } "core-kinds" as kinds
import { * } "core-combinators" as com
import { * } "core-boolean" as bool
import { * } "core-numbers" as num
import { * } "core-strings" as str
import { * } "core-conversions" as conv
import { * } "core-collections" as coll
overload eq as Eq? a
: z... a^s a^r ===[ e... ][ p... ][ True ]==> z... Bool^q
instance eq : Bool
= eq-bool
instance eq : (I8 u)
= eq-i8
instance eq : (U8 u)
= eq-u8
instance eq : (I16 u)
= eq-i16
instance eq : (U16 u)
= eq-u16
instance eq : (I32 u)
= eq-i32
instance eq : (U32 u)
= eq-u32
instance eq : (I64 u)
= eq-i64
instance eq : (U64 u)
= eq-u64
instance eq : (INative u)
= eq-inative
instance eq : (UNative u)
= eq-unative
instance eq : (Single u)
= eq-single
instance eq : (Double u)
= eq-double
instance eq : (String t c)
= eq-string
instance eq : (Rune t c)
= eq-rune
instance eq : <= Eq? y => [y^_]
=
match {
| [] [] => True
| [ ls... l ] [ rs... r ] =>
if l r eq then { [ ls... ] [ rs... ] eq } else { False }
| else => drop drop False
}
instance eq : [| |]
=
match {
| [| |] [| |] => True
}
instance eq : <= Eq? [| a... |], Eq? b => [| a... b^c |]
=
match {
| [| r1... e1 |] [| r2... e2 |] => e1 e2 eq r1 r2 eq and-bool
}
effect iter! a
= yield! : z... a ===[ e..., (iter! a) ][ p... ][ True ]==> z...
overload iterate as Iterate? coll elem
: z... coll ===[ e..., (iter! elem) ][ p... ][ True ]==> z...
rule iterate-fun-dep? = Iterate? coll e1, Iterate? coll e2 => e1 = e2
rule iterate-list? = Iterate? [e1^s]^(s || r) e2 => e1^s = e2
instance iterate : [a^r]^(r || s) a^r
= {
let l;
for el in list l then {
el yield!
}
}
instance iterate : (String t c)^s (Rune t c)^r
= {
let s;
when s length-string 0 gt-inative then {
let w r = s decode-rune-in-string;
r yield!
w s left-slice-string iterate
}
}
overload range as Range? elem
: z... elem^s elem^r elem^q ===[ e..., (iter! elem^t) ][ p... ][ True ]==> z...
instance range : (INative u)
= {
let high low step;
low while dup high lte-inative then {
let current-low;
current-low yield!;
current-low step add-inative
}
drop
}
instance range : (Rune _ _)
= {
let high low step;
low conv-rune-i32 while dup high conv-rune-i32 lte-i32 then {
let current-low;
current-low conv-i32-rune yield!;
current-low step conv-rune-i32 add-i32
}
drop
}
effect test-check!
= test-check! : z... (INative one)^q Bool^s (String t True)^r ===[ e..., test-check! ][ p... ][ True ]==> z... (INative one)^qq
func test-check-handler test-success test-name failed =
if test-success
then { test-name " succeeded.\n" clear-string }
else { test-name " failed.\n" clear-string }
concat-string
print-string
if test-success then { failed } else { 1 failed add-inative }
export { * }