-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
aith.scroll
366 lines (294 loc) · 8.58 KB
/
aith.scroll
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import ../code/conceptPage.scroll
id aith
name Aith
appeared 2020
creators Superstar64
tags pl
website https://github.com/Superstar64/aith
conceptDescription Aith is a perfomant systems programming language with am empathises on type systems. As of now Aith is very early stages and very little is implemented.
writtenIn haskell tex make markdown python xml
repoStats
firstCommit 2020
commits 369
committers 1
files 53
newestCommit 2024
country Unknown
originCommunity https://github.com/Superstar64/aith
example
module ::
inline runtimeCall = \f => \x => f (x);
module combinators = {
inline flip = \f => \x => \y => f !y !x;
inline compose = \f => \g => \x => f !(g !x);
inline readerPure = \x => \r => x;
inline readerBind = \m => \f => \r => f !(m !r) !r;
inline readerMap = \f => \m => readerBind !m !(compose !readerPure !f);
};
module systemf = {
inline ignored <B : type> : <A : type> B -> B;
inline ignored <B : type> = <A : type> \(x : B) => x;
inline idSysF = <A : type> \x : A => x;
inline runIdSysF = \f {
|< f : <A : type> A -> A >|
};
inline id = runIdSysF !idSysF;
type natural = <A : type> A -> (A -> A) -> A;
inline zero<> : natural;
inline zero = <A : type> \z : A => \inc : A -> A => z;
inline inc<> : natural -> natural;
inline inc = \n => <A : type> \z : A => \inc : A -> A => inc !(|< n : natural >| !z !inc);
inline one<> : natural;
inline one = inc !zero;
inline two<> : natural;
inline two = inc !one;
};
module varSub = {
inline sub<R : pretype<pointer, unrestricted>, A : region, B : region >= A, C:type>
: R in A -> R in B -> C -[linear]> C;
inline sub = \a => \b => \x => x;
inline cycle = \a => \b => \c {
sub !a !b !(
sub !b !c !(
sub !c !a !(
\x => x
)
)
)
};
};
module default = {
add = function(x,y) {
x + y
};
ambigous = function(x) {
inline y = 1;
x
};
};
module unit = {
idUnit = function () {
()
};
};
module boolean = {
inline yes = true;
branch = function(b) {
if b {
1
} else {
2
}
};
complex = function(b) {
if (if (b) { true } else {false} ) {
1
} else {
if yes {
2
} else {
4
}
}
};
not = function(b) {
!b
};
inBounds = function(x1, x2, x3) {
x1 <= x2 & x2 < x3
};
};
module pair = {
fst = function(x, y) => x;
snd = function(x, y) => y;
pattern = function (pair) {
(fst(pair), snd(pair))
};
};
module ptr = {
derefTriple = function(x) {
***x
};
deref <RA : region, RB : region >= RA, T : pretype<pointer, unrestricted>> : function (T* @ RA) => T uses RB;
deref <RA : region, RB : region >= RA, T : pretype<pointer, unrestricted>> = function (x) {
*x
};
write<A:region, B:region >= A> : function(int* @ A) => () uses B;
write<A:region, B:region >= A> = function(x :: int* @ A) {
*x = (1 :: int)
};
writeTriple = function(x) {
***x = 1
};
swap = function(x,y) {
let xp = *x;
*x = (*y);
*y = xp;
()
};
};
module number = {
type point = (int, int, int);
dotProduct <R : region> : function(point, point) => int uses R;
dotProduct = function((x1,y1,z1), (x2, y2, z2)) {
(x1 * x2 + y1 * y2 + z1 * z2)
};
mid <R : region> : function(uint, uint) => uint uses R;
mid <R : region> = function(x,y) {
(x + y) / 2
};
inline divGen = function(x,y) {
(x + y - 1) / y
};
div = divGen;
lessEqual = function(x,y) {
x <= y
};
factorial<R : region> : function(ulong) => ulong uses R;
factorial<R : region> = function(x) {
if (x == 0) {
1
} else {
x * factorial (x - 1)
}
};
};
module fptr = {
call = function(f) {
f (1)
};
callUnit <R : region> : function(function*(uint) => () uses R) => () uses R;
callUnit <R : region> = function(f) {
f (2)
};
};
module recurse = {
explode<L : multiplicity, R:region, A:pretype<pointer, L>> : function() => A uses R;
explode<L : multiplicity, R:region, A:pretype<pointer, L>> = function() {
explode ()
};
};
module world = {
inline putchar<A:region> : function*(int) => int uses io in A;
inline putchar<A:region> = extern "putchar";
putPtr<A:region >= io> : function(int* @ A) => int uses A;
putPtr = function(ptr) {
putchar (*ptr)
};
};
module arrays = {
inline get = \x => \i {
* &* &x[i]
};
inline set = \x => \i => \a {
* &* &x[i] = a
};
swap = function(a, b, i) {
let tmp = get !a !i;
set !a !i !(get !b !i);
set !b !i !tmp;
()
};
memcpyPtr = function(dst, src, i) {
loop (let (dst, src, i) = (dst, src, i)) {
if(i != 0) {
* &* dst = (* &* src);
continue (&dst[1], &src[1], i - 1)
} else {
break ()
}
}
};
};
module sort = {
inline get = /arrays/get;
inline set = /arrays/set;
insert<R : region> : function(int[] @ R, unsigned integer(native)) => () uses R;
insert<R : region> = function(array, index) {
loop (let (array, index) = (array,index)) {
if (index > 0 & get !array !index < get !array !(index - 1) ) {
let tmp = get !array !index;
set !array !index !(get !array !(index - 1));
set !array !(index - 1) !tmp;
continue (array, index - 1)
} else {
break ()
}
}
};
sort <R : region> : function(int[] @ R, unsigned integer(native)) => () uses R;
sort <R : region> = function(array, length) {
if (length > 1) {
sort(array, length - 1);
insert(array, length - 1)
} else {
()
}
};
};
module borrowed = {
increment <R : region> : function(unique int*) => unique int* uses R;
increment <R : region> = function(p :: unique int*) {
let ((), p) = borrow p as <A : region >= R>(x :: int* @ A) {
*x = (*x + 1)
};
p
};
};
module partial = {
inline auto = \x => x;
inline semi<A : type> = \x : A => x;
inline scoped<A : type> : A -> A;
inline scoped = \x : A => x;
inline manual<A : type> : A -> A;
inline manual<A : type> = \x => x;
};
module import = {
inline id = \x => x;
module b = {
inline const = \y => /import/id;
};
};
module levity = {
idPolyPair<A : pretype<struct(pointer, 32bit word) ,linear>> = function(x :: A) {
x
};
idPolyUnion<A : pretype<union(pointer, 32bit word) ,linear>> = function(x :: A) {
x
};
useId = function(ptr) {
idPolyPair(ptr, 0)
};
};
module sum = {
triangular = function(start, end) {
loop (let (i, total) = (start, 0)) {
if (i <= end) {
continue (i + 1, total + i)
} else {
break (total)
}
}
};
};
module newtype = {
wrapper num : pretype<32bit word, unrestricted>;
wrapper num = int;
makeNum = function() {
wrap 1 :: num
};
wrapper linked : pretype<pointer, unrestricted>;
wrapper linked = linked2* @ io;
type linked2 = linked;
read = function (x) {
*unwrap (x :: linked)
};
};
keywords as bool borrow boxed break byte capacity continue copy else existence extern false function if in inline int integer invariant io kind let linear long loop module multiarg multiplicity native opaque pointer pretype region representation short signed signedness size step struct subtypable transparent true type ubyte uint ulong union unique unrestricted unsigned unwrap used uses ushort word wrap wrapper
githubRepo https://github.com/Superstar64/aith
stars 41
forks 0
subscribers 5
created 2020
updated 2022
description [Early Stages] Low level functional programming language with linear types, first class inline functions, levity polymorphism and regions.