-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcur.coast
85 lines (75 loc) · 1.85 KB
/
cur.coast
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
a is function[int int int] = fn x y {
x + y
};
adder is function[int int] = fn x {
x + x;
};
l is function[int unit] = fn x {
print "x is: " x;
};
ll = fn idx value {
print "x at offset " idx " is " value;
}
# this is an interesting one; in Python,
# char is basically a type alias for strings,
# but in all other languages we support, it will
# be a completely different type. Unifying those
# two will be interesting...
s is function[char unit] = fn x {
print "x is: " x;
};
b is int = 10;
g = array-make 10 0;
h = array-init 10 adder;
m = array-make-matrix 5 6 0;
f = array-map adder h;
j = array-map-index a h;
# so techincally we can put an `fn` here
# but the current python transpiler doesn't handling
# lifting/closure conversion yet, so I'm being explicit with
# manual lifting myself
array-iter l f;
array-iter-index ll f;
string-iter s "hello, world";
# NOTE need to fix the indentation here
# NOTE need to make sure that things that return `unit` aren't
# prepended with `return`
a-i-func = fn l f {
array-iter l f;
};
a-i-func l f;
blah = fn x {
x < 10;
}
array-iter-while blah print [1 2 3 4 5 6 7 8 9 10 11 12 13];
filter = fn x {
x != ' '
}
test-string-while = fn x y {
string-iter-while x y "this is a test string";
}
test-string-while filter print;
# XXX this currently generates dataclasses
# with typed parameter names; we have two
# real choices here for when we lower to
# Python:
#
# . use `typing.Any` instead of the parameterized type
# . monomorphize types
#
# I think we should give users the options in compiler
# flags to handle it how they'd like...
type Result[A B]
| Ok is [A]
| Err is [B]
epyt;
res_or_err = fn x {
case x
| 10 { Result.Ok "ten" }
| 11 { Result.Ok "11" }
| _ { Result.Err "not ten or 11" }
esac
};
print (res_or_err 10) ;
print (res_or_err 11) ;
print (res_or_err 12)