-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.ml
135 lines (95 loc) · 2.11 KB
/
basic.ml
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
// type Span = (Int, Int, ())
type TypeKind =
| I32
| F32
| TypeRef of String
closed typeclass Expr<Phase: Parsed | TypeChecked> begin
sourceSpan :: Self -> Span -> (Foo -> Bar, Int)
[TypeChecked]
exprType :: Self -> TypeKind
type FuncCall = {
ident: String,
params: String,
[TypeChecked]
retType: TypeKind
}
impl sourceSpan for FuncCall f = f.ident.1
impl exprType for FuncCall f = f.retType
end
test_curry :: String -> String -> () -> (String, String)
test_curry a b =
\_ -> (a, b)
test :: (() -> (String, String)) -> String -> (String, String, String)
test f c =
let r = f ()
(r.0, r.1, c)
type SOption =
| Some of String
| None
main_options :: () -> String
main_options () =
// test (test_curry "din" "mor") "gey"
let opt = SOption.Some "din mor"
// let opt = SOption.None
match opt with
| Some s -> (test (test_curry "din" "mor") s).2
| None -> "Wasn't"
type SList =
| Cons of (String, SList)
| End
main_slists () =
let list = SList.Cons ("mor", SList.Cons ("din", SList.End ()))
list
double :: Int -> Int
double x = x + x
test_nums_ops :: () -> Int
test_nums_ops () =
(5 - 2) * double 7 + 3 * 7 + 9 / 2
test_cond :: Int -> Int
test_cond i =
if i > 5 then
i + i
else
i * i
type Op =
| Add of Int
| Sub of Int
type OpList =
| Cons of (Op, OpList)
| Nil
apply_op :: Op -> Int -> Int
apply_op op a =
match op with
| Add b -> a + b
| Sub b -> a - b
apply :: OpList -> Int -> Int
apply oplist init =
match oplist with
| Cons cons -> apply cons.1 (apply_op cons.0 init)
| Nil -> init
type List 'a =
| Cons of ('a, List 'a)
| Nil
val map: ('a -> 'b) -> List 'a -> List 'b
let map f list =
let x = someExpr in
match list with
| Cons a ->
List.Cons (f a.0, map f a.1)
| Nil ->
List.Nil ()
let main () =
let someList = List.Cons (7, List.Cons (5, List.Nil ()))
map (\x -> printi x) someList
class T = ...
foo :: 'a -> int
foo ('a: Num) :: 'a -> 'a -> int
foo ('a: Num, 'b: Num) :: 'a -> 'b -> int
foo :: ^Num -> ^Num -> int
foo :: T t => t -> int
list :: IComparable[]
map foo list
&[T]
(Num a, Num b) => a -> b
Num -> Num
fn(a: impl Display, b: impl Display) {}