Skip to content

Commit 135ace0

Browse files
committed
some further beautify
1 parent df32cf8 commit 135ace0

19 files changed

+224
-43
lines changed

hkmc2/shared/src/test/mlscript/nofib/NofibPrelude.mls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Tup6[out T1, T2, T3, T4, T5, T6](fst: T1, snd: T2, thd: T3, fth: T4, ffth:
6060
class Tup7[out T1, T2, T3, T4, T5, T6, T7](fst: T1, snd: T2, thd: T3, fth: T4, ffth: T5, sxth: T6, svth: T7)
6161
class Tup8[out T1, T2, T3, T4, T5, T6, T7, T8](fst: T1, snd: T2, thd: T3, fth: T4, ffth: T5, sxth: T6, svth: T7, eghth: T8)
6262

63-
fun (.) compose(f, g) = x => f(g(x))
63+
fun compose(f, g) = x => f(g(x))
6464

6565
fun snd(x) = if x is Tup2(f, s) then s
6666
fun fst(x) = if x is Tup2(f, s) then f
@@ -76,7 +76,7 @@ fun power(a, n) = globalThis.Math.pow(a, n)
7676
fun intDiv(a, b) = globalThis.Math.floor(a / b)
7777
fun intQuot(a, b) = globalThis.Math.trunc(a / b)
7878

79-
fun (%) intMod(a, b) = a - (b * intDiv(a, b))
79+
fun intMod(a, b) = a - (b * intDiv(a, b))
8080
fun intRem(a, b) = a - (b * intQuot(a, b))
8181

8282
fun quotRem(a, b) = Tup2(intQuot(a, b), intRem(a, b))
@@ -138,7 +138,7 @@ fun inList(x, ls) = if ls is
138138

139139
fun notElem(x, ls) = not(inList(x, ls))
140140

141-
fun (++) append(xs, ys) = if xs is
141+
fun append(xs, ys) = if xs is
142142
Nil then ys
143143
Cons(x, xs) then Cons(x, append(xs, ys))
144144

hkmc2/shared/src/test/mlscript/nofib/atom.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:js
22
:import NofibPrelude.mls
3-
//│ Imported 112 member(s)
3+
//│ Imported 109 member(s)
44

55

66
class State(position: List[Num], velocity: List[Num])

hkmc2/shared/src/test/mlscript/nofib/awards.mls

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:js
22
:import NofibPrelude.mls
3-
//│ Imported 112 member(s)
3+
//│ Imported 109 member(s)
44

55

66
fun delete_(xs, e) = deleteBy((x, y) => x == y, e, xs)
@@ -41,10 +41,13 @@ fun perms(m, nns) = if
4141

4242
fun awards(scores) =
4343
let sumscores = map(p => Tup2(sum(p), p), perms(3, scores))
44+
4445
fun atleast(threshold) =
4546
filter(sum_p => if sum_p is Tup2(sum_, p) then sum_ >= threshold, sumscores)
47+
4648
fun award(name_threshold) = if name_threshold is Tup2(name, threshold) then
4749
map(ps => Tup2(name, ps), sort(atleast(threshold)))
50+
4851
append(append(award(Tup2("Gold", 70)), award(Tup2("Silver", 60))), award(Tup2("Bronze", 50)))
4952

5053
fun findawards(scores) = if awards(scores) is
@@ -62,7 +65,7 @@ fun competitors(i) =
6265
Tup2("Kevin", 9::23::17::54::i::41::9::18::14::Nil) :: Nil
6366

6467
fun testAwards_nofib(n) =
65-
map(x => nofibPrint(findallawards(competitors(x % 100)).toString()), enumFromTo(1, n))
68+
map(x => nofibPrint(findallawards(competitors(intMod(x, 100))).toString()), enumFromTo(1, n))
6669

6770

6871
// NOTE: original input 1000

hkmc2/shared/src/test/mlscript/nofib/banner.mls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:js
22
:import NofibPrelude.mls
3-
//│ Imported 112 member(s)
3+
//│ Imported 109 member(s)
44

55

66
let blank =
@@ -128,11 +128,13 @@ fun isSpace(c) =
128128
(n == 32)
129129

130130
fun picChar(c) =
131+
131132
fun lscomp(ls) = if ls is
132133
Nil then Nil
133134
Cons(h, t) and
134135
h is Tup2(c_, letter) and c_ === c then Cons(letter, lscomp(t))
135136
else lscomp(t)
137+
136138
if
137139
isUpper(c) then atIndex(int_of_char(c) - int_of_char("A"), alphas)
138140
isLower(c) then atIndex(int_of_char(c) - int_of_char("a"), alphas)

hkmc2/shared/src/test/mlscript/nofib/boyer.mls

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:js
22
:import NofibPrelude.mls
3-
//│ Imported 112 member(s)
3+
//│ Imported 109 member(s)
44

55

66
abstract class Id: A | B | C | D | X | Y | Z | U | W | ADD1 | AND | APPEND | CONS | CONSP | DIFFERENCE | DIVIDES | EQUAL | EVEN | EXP | F | FALSE | FOUR | GCD | GREATEREQP | GREATERP | IF | IFF | IMPLIES | LENGTH | LESSEQP | LESSP | LISTP | MEMBER | NIL | NILP | NLISTP | NOT | ODD | ONE | OR | PLUS | QUOTIENT | REMAINDER | REVERSE | SUB1 | TIMES | TRUE | TWO | ZERO | ZEROP
@@ -165,76 +165,116 @@ fun test0(xxxx) =
165165
let nil = Fun(NIL , Nil, lazy of () => Nil)
166166
let boyerTrue = Fun(TRUE , Nil, lazy of () => Nil)
167167
let zero = Fun(ZERO , Nil, lazy of () => Nil)
168+
168169
fun one() = Fun(ONE, Nil, lazy of () => Cons(Tup2(one(), add1(zero)), Nil))
170+
169171
fun two() = Fun(TWO, Nil, lazy of () => Cons(Tup2(two(), add1(one())), Nil))
172+
170173
fun four() = Fun(FOUR, Nil, lazy of () => Cons(Tup2(four(), add1(add1(two()))), Nil))
174+
171175
fun add1(a) = Fun(ADD1, a :: Nil, lazy of () => Nil)
176+
172177
fun if_(a, b, c) = Fun(IF, Cons(a, Cons(b, Cons(c, Nil))), lazy of () => Cons(Tup2(if_(if_(x, y, z), u, w), if_(x, if_(y, u, w), if_(z, u, w))), Nil))
178+
173179
fun not_(a) = Fun(NOT, a :: Nil, lazy of () => Tup2(not_(x), if_(x, boyerFalse, boyerTrue)) :: Nil)
180+
174181
fun and_(a, b) =
175182
Fun(AND, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(and_(x, y), if_(x, if_(y, boyerTrue, boyerFalse), boyerFalse)), Nil))
183+
176184
fun append_(a, b) =
177185
Fun(APPEND, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(append_(append_(x, y), z), append_(x, append_(y, z))), Nil))
186+
178187
fun cons(a, b) =
179188
Fun(CONS, Cons(a, Cons(b, Nil)), lazy of () => Nil)
189+
180190
fun consp(a) =
181191
Fun(CONSP, Cons(a, Nil), lazy of () => Cons(Tup2(consp(cons(x, y)), boyerTrue), Nil))
192+
182193
fun difference(a, b) =
183194
Fun(DIFFERENCE, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(difference(x, x), zero), Cons(Tup2(difference(plus(x, y), x), y), Cons(Tup2(difference(plus(y, x), x), y), Cons(Tup2(difference(plus(x, y), plus(x, z)), difference(y, z)), Cons(Tup2(difference(plus(y, plus(x, z)), x), plus(y, z)), Cons(Tup2(difference(add1(plus(y, z)), z), add1(y)), Cons(Tup2(difference(add1(add1(x)), two()), x), Nil))))))))
195+
184196
fun divides(a, b) =
185197
Fun(DIVIDES, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(divides(x, y), zerop(remainder(y, x))), Nil))
198+
186199
fun equal(a, b) =
187200
Fun(EQUAL, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(equal(plus(x, y), zero), and_(zerop(x), zerop(y))), Cons(Tup2(equal(plus(x, y), plus(x, z)), equal(y, z)), Cons(Tup2(equal(zero, difference(x, y)), not_(lessp(y, x))), Cons(Tup2(equal(x, difference(x, y)), or_(equal(x, zero), zerop(y))), Cons(Tup2(equal(times(x, y), zero), or_(zerop(x), zerop(y))), Cons(Tup2(equal(append_(x, y), append_(x, z)), equal(y, z)), Cons(Tup2(equal(y, times(x, y)), or_(equal(y, zero), equal(x, one()))), Cons(Tup2(equal(x, times(x, y)), or_(equal(x, zero), equal(y, one()))), Cons(Tup2(equal(times(x, y), one()), and_(equal(x, one()), equal(y, one()))), Cons(Tup2(equal(difference(x, y), difference(z, y)), if_(lessp(x, y), not_(lessp(y, z)), if_(lessp(z, y), not_(lessp(y, x)), equal(x, z)))), Cons(Tup2(equal(lessp(x, y), z), if_(lessp(x, y), equal(boyerTrue, z), equal(boyerFalse, z))), Nil))))))))))))
201+
188202
fun even_(a) =
189203
Fun(EVEN, Cons(a, Nil), lazy of () => Cons(Tup2(even_(x), if_(zerop(x), boyerTrue, odd_(sub1(x)))), Nil))
204+
190205
fun exp_(a, b) =
191206
Fun(EXP, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(exp_(x, plus(y, z)), times(exp_(x, y), exp_(x, z))), Cons(Tup2(exp_(x, times(y, z)), exp_(exp_(x, y), z)), Nil)))
207+
192208
fun f(a) =
193209
Fun(F, Cons(a, Nil), lazy of () => Nil)
210+
194211
fun gcd_(a, b) =
195212
Fun(GCD, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(gcd_(x, y), gcd_(y, x)), Cons(Tup2(gcd_(times(x, z), times(y, z)), times(z, gcd_(x, y))), Nil)))
213+
196214
fun greatereqp(a, b) =
197215
Fun(GREATEREQP, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(greatereqp(x, y), not_(lessp(x, y))), Nil))
216+
198217
fun greaterp(a, b) =
199218
Fun(GREATERP, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(greaterp(x, y), lessp(y, x)), Nil))
219+
200220
fun implies(a, b) =
201221
Fun(IMPLIES, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(implies(x, y), if_(x, if_(y, boyerTrue, boyerFalse), boyerTrue)), Nil))
222+
202223
fun iff(a, b) =
203224
Fun(IFF, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(iff(x, y), and_(implies(x, y), implies(y, x))), Nil))
225+
204226
fun length_(a) =
205227
Fun(LENGTH, Cons(a, Nil), lazy of () => Cons(Tup2(length_(reverse_(x)), length_(x)), Cons(Tup2(length_(cons(x, cons(y, cons(z, cons(u, w))))), plus(four(), length_(w))), Nil)))
228+
206229
fun lesseqp(a, b) =
207230
Fun(LESSEQP, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(lesseqp(x, y), not_(lessp(y, x))), Nil))
231+
208232
fun lessp(a, b) =
209233
Fun(LESSP, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(lessp(remainder(x, y), y), not_(zerop(y))), Cons(Tup2(lessp(quotient(x, y), x), and_(not_(zerop(x)), lessp(one(), y))), Cons(Tup2(lessp(plus(x, y), plus(x, z)), lessp(y, z)), Cons(Tup2(lessp(times(x, z), times(y, z)), and_(not_(zerop(z)), lessp(x, y))), Cons(Tup2(lessp(y, plus(x, y)), not_(zerop(x))), Nil))))))
234+
210235
fun nilp(a) =
211236
Fun(NILP, Cons(a, Nil), lazy of () => Cons(Tup2(nilp(x), equal(x, nil)), Nil))
237+
212238
fun listp(a) =
213239
Fun(LISTP, Cons(a, Nil), lazy of () => Cons(Tup2(listp(x), or_(nilp(x), consp(x))), Nil))
240+
214241
fun member(a, b) =
215242
Fun(MEMBER, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(member(x, append_(y, z)), or_(member(x, y), member(x, z))), Cons(Tup2(member(x, reverse_(y)), member(x, y)), Nil)))
243+
216244
fun nlistp(a) =
217245
Fun(NLISTP, Cons(a, Nil), lazy of () => Cons(Tup2(nlistp(x), not_(listp(x))), Nil))
246+
218247
fun odd_(a) =
219248
Fun(ODD, Cons(a, Nil), lazy of () => Cons(Tup2(odd_(x), even_(sub1(x))), Nil))
249+
220250
fun or_(a, b) =
221251
Fun(OR, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(or_(x, y), if_(x, boyerTrue, if_(y, boyerTrue, boyerFalse))), Nil))
252+
222253
fun plus(a, b) =
223254
Fun(PLUS, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(plus(plus(x, y), z), plus(x, plus(y, z))), Cons(Tup2(plus(remainder(x, y), times(y, quotient(x, y))), x), Cons(Tup2(plus(x, add1(y)), add1(plus(x, y))), Nil))))
255+
224256
fun quotient(a, b) =
225257
Fun(QUOTIENT, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(quotient(plus(x, plus(x, y)), two()), plus(x, quotient(y, two()))), Cons(Tup2(quotient(times(y, x), y), if_(zerop(y), zero, x)), Nil)))
258+
226259
fun remainder(a, b) =
227260
Fun(REMAINDER, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(remainder(x, one()), zero), Cons(Tup2(remainder(x, x), zero), Cons(Tup2(remainder(times(x, y), x), zero), Cons(Tup2(remainder(times(x, y), y), zero), Nil)))))
261+
228262
fun reverse_(a) =
229263
Fun(REVERSE, Cons(a, Nil), lazy of () => Cons(Tup2(reverse_(append_(x, y)), append_(reverse_(y), reverse_(x))), Nil))
264+
230265
fun sub1(a) =
231266
Fun(SUB1, Cons(a, Nil), lazy of () => Cons(Tup2(sub1(add1(x)), x), Nil))
267+
232268
fun times(a, b) =
233269
Fun(TIMES, Cons(a, Cons(b, Nil)), lazy of () => Cons(Tup2(times(x, plus(y, z)), plus(times(x, y), times(x, z))), Cons(Tup2(times(times(x, y), z), times(x, times(y, z))), Cons(Tup2(times(x, difference(y, z)), difference(times(y, x), times(z, x))), Cons(Tup2(times(x, add1(y)), plus(x, times(x, y))), Nil)))))
270+
234271
fun zerop(a) =
235272
Fun(ZEROP, Cons(a, Nil), lazy of () => Cons(Tup2(zerop(x), equal(x, zero)), Nil))
273+
236274
let subst0 = Cons(Tup2(X, f(plus(plus(a, b), plus(c, zero)))), Cons(Tup2(Y, f(times(times(a, b), plus(c, d)))), Cons(Tup2(Z, f(reverse_(append_(append_(a, b), nil)))), Cons(Tup2(U, equal(plus(a, b), difference(x, y))), Cons(Tup2(W, lessp(remainder(a, b), member(a, length_(b)))), Nil)))))
275+
237276
let theorem = implies(and_(implies(xxxx, y), and_(implies(y, z), and_(implies(z, u), implies(u, w)))), implies(x, w))
277+
238278
tautp(apply_subst(subst0, theorem))
239279

240280
fun testBoyer_nofib(n) = all(test0, replicate(n, Var(X)))

hkmc2/shared/src/test/mlscript/nofib/calendar.mls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:js
22
:import NofibPrelude.mls
3-
//│ Imported 112 member(s)
3+
//│ Imported 109 member(s)
44

55

66
fun unlines(ls) = concat(map(x => append(x, ("\n" :: Nil)), ls))
@@ -79,6 +79,7 @@ fun cal(year) =
7979
fun table(fd, ml) = append(daynames, entries(fd, ml))
8080
fun entries(fd, ml) = block(7, dates(fd, ml))
8181
fun months(yer) = zip3(monthNames, firstDays(yer), monthLengths(yer))
82+
8283
unlines(append(banner(year), body(year)))
8384

8485
fun testCalendar_nofib(n) = map(x => cal(x), enumFromTo(1993, 1993 + n))

0 commit comments

Comments
 (0)