forked from Fundament-Institute/Alicorn0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplecode.alc
More file actions
51 lines (44 loc) · 792 Bytes
/
Copy pathsamplecode.alc
File metadata and controls
51 lines (44 loc) · 792 Bytes
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
fn add
from x : i32 y : i32
to i32
+ x y
fn ex1
from x : i32
to i32
val y = (* x 2)
val z =
if (x < 5)
/ x 2
+ x y
+ y z
# variables can remain in scope past a conditional
fn ex2
from x : i32
to i32
if (x < 5)
val y = (* x 2)
val y = x
+ x y
# if a variable is declared in all branches of a conditional with compatible types, it can exit the conditional via the distributive law
fn ex3
from x : i32
to i32
val y = (* x 2)
if (x < 5)
do
val y = x
;
;
+ x y
# as a consequence, if a variable is shadowed with the same type in one branch a conditional, then it may exit the conditional with a rebound value
cond
(== x 1)
foo bar
(== x 2)
foo baz
true
"default"
if ( == x 2 )
foo bar
else
foo baz