forked from hkust-taco/mlscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic2.mls
78 lines (60 loc) · 1.72 KB
/
Basic2.mls
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
:NewDefs
:NoJS
// More specific checks from parser folder
let res = code"[]"
//│ let res: Code[[], nothing]
run(res)
//│ []
let res = code"()"
run(res)
//│ let res: Code[(), nothing]
//│ ()
let res = code"(1,)"
run(res)
//│ let res: Code[1, nothing]
//│ 1
let res = code"let f = (x, y, z) => x + y + x in f of 1,2,3"
run(res)
//│ let res: Code[Int, nothing]
//│ Int
//any of a, b, c -> codegen error from unresolved symbol "any"
:pe
code"// Can I comment?"
//│ ╔══[PARSE ERROR] Unmatched opening quasiquote
//│ ║ l.29: code"// Can I comment?"
//│ ╙── ^^^^^
//│
let res = code"[x: 1,]"
//│ let res: Code[[x: 1], nothing]
run(res)
//│ [x: 1]
// :ge
:e
code"let x = {a: 100} in x . a" // "." ?
//│ ╔══[ERROR] unbound quoted variable: .
//│ ║ l.42: code"let x = {a: 100} in x . a" // "." ?
//│ ╙── ^
//│ ╔══[ERROR] unbound quoted variable: a
//│ ║ l.42: code"let x = {a: 100} in x . a" // "." ?
//│ ╙── ^
//│ Code[error, nothing]
code"let x = {a: 100} in x.a"
//│ Code[100, nothing]
// should be ok
let res = code"let x = {a: 100} in x .a"
//│ let res: Code[100, nothing]
run(res)
//│ 100
let app = code"f => x => f(x)"
run(app)(id)(1)
//│ let app: Code[forall 'a 'b. ('a -> 'b) -> 'a -> 'b, nothing]
//│ 1
:e
code"f => x => f(${run(x)})"
//│ ╔══[ERROR] Type mismatch in application:
//│ ║ l.69: code"f => x => f(${run(x)})"
//│ ║ ^^^^^^
//│ ╙── expression of type `?x` does not match type `nothing`
//│ Code[forall 'a 'b. ('a -> 'b) -> Code['a, anything] -> 'b, nothing]
run(code"(x => x + 1)(${Const(42)})")
//│ Int