-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.spl
86 lines (81 loc) · 1.89 KB
/
sample.spl
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
data Foo = { Bar Double }
data MaybeI = { JustI Double | Nothing }
# data Barbar a = { Asdf Int a }
# fun id (x : a) : a := { x }
#
# fun eqargs (x : a, y : a, z: b) : a := { x }
fun main : Int := { let x = &asdf in 5 }
# fun not (b : Bool) : Bool := { if b then false else true }
#
# fun and (p : Bool, q : Bool) : Bool := { if p then (if q then true else false) else false }
#
# fun or (p : Bool, q : Bool) : Bool := { if p then true else (if q then true else false) }
#
# fun factorial (x : Int) : Int := {
# if (x <= 0) then 1
# else x * @factorial(x - 1)
# }
#
# fun even (x: Int) : Bool := {
# if (x <= 0) then true
# else @not(@odd(x - 2))
# }
#
# fun odd (x: Int) : Bool := {
# if (x <= 1) then true
# else @not(@even(x - 2))
# }
#
# fun nested_ifs : Double := {
# (if true then (if true then 4.0 else 5.0) else (if false then 2.0 else 3.0) + 1.0) * 2.0
# }
#
# fun main : Int := {
# case JustI 10.0 of
# JustI x =>
# let msg = println("In Just branch") in
# let mynum = @abs(-1) in
# (if (@even(4)) then @double_me(5) else @factorial(6)) * @asdf * mynum
# Nothing =>
# let msg = println("In Nothing branch") in
# let res = 4 in
# @double_me(res + 1)
# }
#
# fun asdf : Int := {
# (if false then 5 else 10) + 2
# }
#
# fun double_me (x : Int) : Int := { x * 2 }
#
# fun foo : Foo := {
# Bar 5.0
# }
#
# fun foo2 : Bool := {
# case Bar 5.0 of
# Bar x => true
# }
#
# fun lots_of_lets : Double := {
# let x = if true then 1.0 else 2.0 in
# let y = if true then x * 2.0 else x * 2.0 + 1.0 in
# y
# }
#
# fun fun_ptr : Int -> Int := { &double_me }
#
# fun fun_ptr_test (b : Bool) : Int := {
# let f = if b then &double_me else &factorial in
# @f(4)
# }
#
# fun cast_test_1 : Int := {
# (1 + 1) * (cast 2.0 as Int)
# }
#
# fun cast_test_2 : Int := {
# (1 * 1) + (cast 2.0 as Int)
# }
#
# fun abs (x : Int) : Int := extern