Skip to content

Commit 4b3fa86

Browse files
committed
Deduplicate predefined libraries
1 parent e5a8311 commit 4b3fa86

File tree

11 files changed

+29
-79
lines changed

11 files changed

+29
-79
lines changed

hkmc2/shared/src/test/mlscript-compile/List.mjs

Lines changed: 0 additions & 31 deletions
This file was deleted.

hkmc2/shared/src/test/mlscript-compile/List.mls

Lines changed: 0 additions & 5 deletions
This file was deleted.

hkmc2/shared/src/test/mlscript-compile/Stack.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module Stack with ...
66

7-
class Cons[A](head: A, tail)
7+
class (::) Cons[A](head: A, tail)
88
module Nil
99

1010
fun isEmpty(xs) = xs is Nil

hkmc2/shared/src/test/mlscript-compile/Str.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const Str$class = class Str {
44
}
55
concat(a, b) {
66
return a + b;
7+
}
8+
string(value) {
9+
return globalThis.String(value);
710
}
811
toString() { return "Str"; }
912
}; const Str = new Str$class;

hkmc2/shared/src/test/mlscript-compile/Str.mls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ module Str with ...
33

44
fun (~) concat(a, b) = a + b
55

6+
fun string(value) = globalThis.String(value)

hkmc2/shared/src/test/mlscript-compile/String.mjs

Lines changed: 0 additions & 14 deletions
This file was deleted.

hkmc2/shared/src/test/mlscript-compile/String.mls

Lines changed: 0 additions & 6 deletions
This file was deleted.

hkmc2/shared/src/test/mlscript/ucs/examples/EitherOrBoth.mls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import "../../../mlscript-compile/String.mls"
1+
import "../../../mlscript-compile/Str.mls"
22
import "../../../mlscript-compile/Option.mls"
33

44
open Option
5-
open String
5+
open Str
66

77
abstract class EitherOrBoth[out A, out B]: (Left[A, B] | Right[A, B] | Both[A, B])
88
class Left[out A, out B](value: A) extends EitherOrBoth[A, B]
@@ -73,6 +73,6 @@ fun isBoth[A, B](eob: EitherOrBoth[A, B]): Bool =
7373

7474
fun eobToString[A, B](eob: EitherOrBoth[A, B]): Str =
7575
if eob is
76-
Left(left) then "Left(" ++ toString(left) ++ ")"
77-
Right(right) then "Right(" ++ toString(right) ++ ")"
78-
Both(left, right) then "Both(" ++ toString(left) ++ ", " ++ toString(right) ++ ")"
76+
Left(left) then "Left(" ~ string(left) ~ ")"
77+
Right(right) then "Right(" ~ string(right) ~ ")"
78+
Both(left, right) then "Both(" ~ string(left) ~ ", " ~ string(right) ~ ")"

hkmc2/shared/src/test/mlscript/ucs/examples/ListFold.mls

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import "../../../mlscript-compile/List.mls"
1+
import "../../../mlscript-compile/Stack.mls"
22
import "../../../mlscript-compile/Option.mls"
3-
import "../../../mlscript-compile/String.mls"
3+
import "../../../mlscript-compile/Str.mls"
44

5-
open List
5+
open Stack
66
open Option
7-
open String
7+
open Str
88

99
fun (|>) pipe(x, f) = f(x)
1010

@@ -24,16 +24,16 @@ fun join(sep) =
2424
fun aux(acc, xs) =
2525
if xs is
2626
Nil then acc
27-
Cons(x, xs') then aux(acc ++ sep ++ toString(x), xs')
27+
Cons(x, xs') then aux(acc ~ sep ~ string(x), xs')
2828
(xs) =>
2929
if xs is
30-
Cons(x, xs') then aux(toString(x), xs')
30+
Cons(x, xs') then aux(string(x), xs')
3131
Nil then ""
3232

3333
join(", ")(1 :: 2 :: 3 :: Nil)
3434
(1 :: 2 :: 3 :: Nil) |> join(", ")
3535

36-
fun showList(xs) = "[" ++ join(", ")(xs) ++ "]"
36+
fun showList(xs) = "[" ~ join(", ")(xs) ~ "]"
3737

3838
fun (:::) appendAll(xs, ys) =
3939
if xs is

hkmc2/shared/src/test/mlscript/ucs/examples/Permutations.mls

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import "../../../mlscript-compile/List.mls"
2-
import "../../../mlscript-compile/String.mls"
1+
import "../../../mlscript-compile/Stack.mls"
2+
import "../../../mlscript-compile/Str.mls"
33

4-
open List
5-
open String
4+
open Stack
5+
open Str
6+
7+
type List[A] = Nil | Cons[A]
68

79
fun (|>) pipe(x, f) = f(x)
810

@@ -21,12 +23,12 @@ fun join(sep) =
2123
fun aux(acc, xs) =
2224
if xs is
2325
Nil then acc
24-
Cons(x, xs') then aux(acc ++ sep ++ toString(x), xs')
26+
Cons(x, xs') then aux(acc ~ sep ~ string(x), xs')
2527
(xs) =>
2628
if xs is
27-
Cons(x, xs') then aux(toString(x), xs')
29+
Cons(x, xs') then aux(string(x), xs')
2830
Nil then ""
29-
fun showList(xs) = "[" ++ join(", ")(xs) ++ "]"
31+
fun showList(xs) = "[" ~ join(", ")(xs) ~ "]"
3032
fun foldLeft(f)(z) =
3133
fun aux(acc, xs) =
3234
if xs is
@@ -37,7 +39,7 @@ fun map(f, xs) =
3739
if xs is
3840
Nil then Nil
3941
Cons(x, xs') then f(x) :: map(f, xs')
40-
fun showListList(xs) = "[" ++ join(", ")(map(showList, xs)) ++ "]"
42+
fun showListList(xs) = "[" ~ join(", ")(map(showList, xs)) ~ "]"
4143

4244
fun insertAllPositions(z) =
4345
fun aux(prev, acc, xs) =

hkmc2/shared/src/test/mlscript/ucs/normalization/UnifySubScrutinees.mls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "../../../mlscript-compile/List.mls"
1+
import "../../../mlscript-compile/Stack.mls"
22
import "../../../mlscript-compile/Option.mls"
33

4-
open List
4+
open Stack
55
open Option
66

77
:global

0 commit comments

Comments
 (0)