-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.junu
192 lines (148 loc) · 4.52 KB
/
test.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
type Pet = {species: String, name: String, color: String}
type Moo = {name: String, age: Num, male: Bool, pet: Pet}
type Person = {name: String, age: Num, male: Bool, pet: Pet, parent: Nil | Person}
type Date = {month: Num, weekday: Num, year: Num}
newtype Tup(a{}, b{}) = (a, b)
println("\n\n\nProgram begins: \n")
let s = Tup(1, true)
let x = s.a
let b = s.b
x = 4
let i = 0
let fl = (a: Num, b: Bool) => {
return (n: Bool) => {
return (h: Pet) => {
return () => {
return h.name
}
}
}
}
let go = (a: Num, b: Num) => {
let f = (n: Num) => {
let zoo = n * 3
return n
}
let ans = a+b
return f(ans)
}
mutu1(Num, Num) => Num
mutu2(Num, Bool) => Num
mutu1 = (a: Num, b: Num) => Num {
return mutu2(b, true)
}
mutu2 = (n: Num, a: Bool) => Num {
if b { return 1 }
return mutu1(n, n+1)
}
let apply = (f: (a{}) -> b{}, x: a{}) => b{} {
return f(x)
}
let given = fl(1, true)(true)({name: "Hello's kitty", color: "Black", species: "Cat"})()
let application = apply((a: Num) => { return a == 1 }, 1)
let changeCatName = (person: Person, name: String) => {
let f = () => {
if person.age < 5 {
let catties = 1
catties = catties + 1
person.pet.name = person.name
return person.pet.name
} else if person.age < 100 {
person.pet.name = name
return person.pet.name
} else {
return "Dead man's cat"
}
}
return f()
}
let modifyAge = (person: Person, age: Num) => {
person.age = if age < 0 then 0 else age
return age
}
let st = {name: "Ameer", age: 10, male: true, pet: {species: "Cat", name: "Tom", color: "White"}, parent: {}}
st.parent = duplicate(st)
let nm1 = changeCatName(st, "Molly")
let ag1 = modifyAge(st, st.age + 1)
write("st is: ")
println(st)
open setName(t{}, String, a{.pet: b{.name: t{}}}) => b{.name: t{}} for a{.pet: b{.name: t{}}}
impl setName(s: String, area: String, person: Person) => {
person.name = s
return person.pet
} for Person
impl setName(s: String, area: String, cat: {pet: Person}) => {
cat.pet.name = s
return cat.pet
} for {pet: Person}
impl setName(i: Num, area: String, intkeeper: {pet: {name: Num}}) => {
intkeeper.pet.name = i
return intkeeper.pet
} for {pet: {name: Num}}
let sn = setName("Junu", "Collatz", {pet: st})
write("sn is: ")
println(sn)
open fi(a{}) => (a{}) -> a{} for a{}
impl fi(i: Num) => {
return (i: Num) => {return i}
} for Num
let fires = fi(1)
let fn = (c: st{.n: t{}, .a: Num}, a: t{}) => {
c.n = a
return c.n
}
let swapG = (a: x{.a: ax{}, .b: bx{}}, f: (bx{}, ax{}) -> Tup(bx{}, ax{})) => {
return f(a.b, a.a)
}
let swapML = (ml: x{.a: ax{}, .b: bx{}}) => {
return Tup(ml.b, ml.a)
}
fn({n: {month: 2, weekday: 5, year: 1999}, a: 1}, {month: 3, weekday: 5, year: 1999})
let btool = fn({n: false, a: 4, x: "Hello"}, true)
let mlres = swapML(Tup(st, Tup(1, st.pet)))
write("mlres is: ")
println(mlres)
let compose2 = (f: (a{}) -> b{}, g: (b{}) -> c{}) => return (x: a{}) => g(f(x))
let identity = (x: x{}) => {
let f = compose2((x: x{}) => x, (x: i{}) => x)
return f(x)
}
open fst(s{.a: ay{}, .b: by{}}) => ay{} for s{.a: ay{}, .b: by{}}
impl fst(s: Tup(w{}, d{})) => {
return identity(s.a)
} for Tup(w{}, d{})
impl add(a: Pet, b: Pet) => {
return {species: if a.species == b.species then a.species else a.species + " with " + b.species, name: a.name + " " + b.name, color: b.color}
} for Pet
let snd = (s: Tup(l{}, r{})) => fst(swapML(s))
let tres = snd(s)
write("tres is: ")
println(tres)
let idresf = (s: Tup(q{}, k{})) => identity(apply(identity, swapG(s, (a: oi{}, b: fi{}) => Tup(a, b))))
let idres = idresf(s)
write("idres is: ")
println(idres)
let ftr = (a: String, b: {name: String, species: String} | Pet | Person) => String {
let bt = Tup(Tup(b, b), b)
if bt notis Tup(Tup(Person, Person), Person) {
return bt.a.a.species + " " + bt.a.a.name
} else {
return bt.a.a.pet.species + " " + bt.a.a.name
}
return b.name + a
}
let flr = (x: Pet | Person) => {
if x is Person {
return {x: 1}
}
return ftr(x.species, x)
}
if x is Num {
b = if x < 10 then ftr("Hello ", st) else false
}
let basicPerson = (name: String, age: Num, male: Bool) => Person {
return {name: name, age: age, male: male, pet: {species: "Cat", name: "Tom", color: "White"}, parent: {}}
}
let petPlusPet = st.pet + {species: "Dog", name: "Tom", color: "Black"}
write("petPlusPet is: ")
println(petPlusPet)