-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rn
46 lines (37 loc) · 931 Bytes
/
test.rn
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
extern print (x: i32) unit;
extern print1 (x: f32) unit;
let global: i32 = 1 * 1 + 2;
// yeah
fn main -> unit = do {
let f: fn i32 -> unit = (\(x: i32) unit -> print (fac 3));
loop f 20 0;
loop (\(y: i32) unit -> print y) 5 0;
loop \(y: i32) unit -> do { print y; } 5 0;
print (1 - -1);
// print _test' ();
_test' (); // discarded atm, TODO: typecheck?
();
};
fn _test' (_: unit) -> fn -> i32 = do {
let z: i32 = 12;
\i32 -> -z;
};
fn loop(f: fn i32 -> unit) (upper: i32) (lower: i32) -> unit =
if (upper < lower)
()
do {
f upper;
loop f (upper - 1) lower;
}
;
fn run_fac_and_print(x: i32) -> unit = print (fac x);
fn fib (x: i32) -> i32 =
if x <= 1
do { 1; }
fib (x - 1) + fib (x - 2)
;
fn fac (x: i32) -> i32 =
if (x <= 1) and do { print 11; true; }
1
(x * fac (x - 1))
;