-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunionTest.junu
55 lines (42 loc) · 1.21 KB
/
unionTest.junu
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
newtype Ls(x{}, Nil | Ls(x{})) = (r, res)
let base = () => return {}
let insert = (arr: Nil | Array(m{}), a: n{}) => concat(arr, Array(a))
let res = Array(1)
res = insert(insert(res, true), "mooo")
res = concat(res, Array({p: true}))
let sres = insert(res, {b: "Hello"})
sres = concat(sres, Array({a: 3}))
res = concat(res, Array(sres))
println(res)
len(xs: Nil | Ls(n{})) => Num {
if not (xs is Ls(n{})) { return 0 }
return len(xs.res)+1
}
let ins = (a: a{}, ls: Nil | Ls(a{})) => Ls(a, ls)
let concatList = (as: Nil | Ls(z{}), bs: Nil | Ls(z{})) => {
if as is Nil { return bs }
return Ls(as.r, concatList(as.res, bs))
}
let xs = ins(true, ins(1, Ls("ddjn", {})))
xs = ins("ok", xs)
xs = concatList(Ls({x: 8}, {}), xs)
println(len(xs))
let compose2 = (g: (b{}) -> c{}, f: (a{}) -> b{}) => {
return (x: a{}) => g(f(x))
}
let lenApply = compose2((a: hasLength{.length: Num}) => {
a.length = a.length*2
return a
}, (ls: Nil | Ls(k{})) => return {list: ls, length: len(ls)})
let lenApplied = lenApply(xs)
println(lenApplied)
if res notis Nil {
let x = index(res, 3)
if x is String {
println(x + "hoo")
} else if x is Num {
println(x+1)
} else {
println(x)
}
}