@plylang/prelude 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1679 -2
- package/dist/Alt.d.ply +16 -0
- package/dist/Alt.js +2 -0
- package/dist/Alternative.d.ply +13 -0
- package/dist/Alternative.js +16 -0
- package/dist/Applicative.d.ply +23 -0
- package/dist/Applicative.js +18 -0
- package/dist/Apply.d.ply +31 -0
- package/dist/Apply.js +37 -0
- package/dist/Arithmetic.d.ply +83 -0
- package/dist/Arithmetic.js +54 -0
- package/dist/Bifunctor.d.ply +12 -0
- package/dist/Bifunctor.js +13 -0
- package/dist/Chain.d.ply +22 -0
- package/dist/Chain.js +9 -0
- package/dist/Composition.d.ply +16 -0
- package/dist/Composition.js +38 -0
- package/dist/Filterable.d.ply +28 -0
- package/dist/Filterable.js +14 -0
- package/dist/Foldable.d.ply +63 -0
- package/dist/Foldable.js +238 -0
- package/dist/Functor.d.ply +17 -0
- package/dist/Functor.js +12 -0
- package/dist/Group.d.ply +10 -0
- package/dist/Logical.d.ply +37 -0
- package/dist/Logical.js +20 -0
- package/dist/Monad.d.ply +10 -0
- package/dist/Monoid.d.ply +32 -0
- package/dist/Monoid.js +21 -0
- package/dist/Ord.d.ply +67 -0
- package/dist/Ord.js +106 -0
- package/dist/Plus.d.ply +16 -0
- package/dist/Plus.js +13 -0
- package/dist/Prelude.d.ply +47 -0
- package/dist/Prelude.js +15 -0
- package/dist/Semigroup.d.ply +30 -0
- package/dist/Semigroup.js +19 -0
- package/dist/Setoid.d.ply +45 -0
- package/dist/Setoid.js +25 -0
- package/dist/Show.d.ply +45 -0
- package/dist/Show.js +34 -0
- package/dist/Traversable.d.ply +31 -0
- package/dist/Traversable.js +134 -0
- package/dist/Types.d.ply +39 -0
- package/dist/Types.js +8 -0
- package/foreign/Alt.js +3 -0
- package/foreign/Applicative.js +3 -0
- package/foreign/Apply.js +9 -0
- package/foreign/Arithmetic.js +57 -0
- package/foreign/Chain.js +9 -0
- package/foreign/Filterable.js +13 -0
- package/foreign/Foldable.js +29 -0
- package/foreign/Functor.js +3 -0
- package/foreign/Logical.js +11 -0
- package/foreign/Ord.js +34 -0
- package/foreign/Semigroup.js +7 -0
- package/foreign/Setoid.js +24 -0
- package/foreign/Show.js +20 -0
- package/foreign/Traversable.js +3 -0
- package/foreign/Types.js +52 -0
- package/package.json +131 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { concat_str, concat_array } from "../foreign/Semigroup.js";
|
|
2
|
+
export { concat_str, concat_array };
|
|
3
|
+
|
|
4
|
+
export function concat_unit(v0, v1) {
|
|
5
|
+
const v2 = undefined;
|
|
6
|
+
return v2;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function concat_ordering(v3, v4) {
|
|
10
|
+
let v5;
|
|
11
|
+
if (v3.$$tag === "LT") {
|
|
12
|
+
v5 = v3;
|
|
13
|
+
} else if (v3.$$tag === "GT") {
|
|
14
|
+
v5 = v3;
|
|
15
|
+
} else {
|
|
16
|
+
v5 = v4;
|
|
17
|
+
}
|
|
18
|
+
return v5;
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
language 1
|
|
2
|
+
|
|
3
|
+
@ Setoid, equal
|
|
4
|
+
|
|
5
|
+
~ "Types" Ordering, LT, EQ, GT
|
|
6
|
+
|
|
7
|
+
.. Decide whether two values are equal.
|
|
8
|
+
& Setoid a
|
|
9
|
+
.. True when the two values match.
|
|
10
|
+
equal ( a a -- Bool )
|
|
11
|
+
|
|
12
|
+
# Setoid Str
|
|
13
|
+
equal = equal_str
|
|
14
|
+
|
|
15
|
+
: foreign equal_str ( Str Str -- Bool )
|
|
16
|
+
|
|
17
|
+
# Setoid Num
|
|
18
|
+
equal = equal_num
|
|
19
|
+
|
|
20
|
+
: foreign equal_num ( Num Num -- Bool )
|
|
21
|
+
|
|
22
|
+
# Setoid Int
|
|
23
|
+
equal = equal_int
|
|
24
|
+
|
|
25
|
+
: foreign equal_int ( Int Int -- Bool )
|
|
26
|
+
|
|
27
|
+
# Setoid Bool
|
|
28
|
+
equal = equal_bool
|
|
29
|
+
|
|
30
|
+
: foreign equal_bool ( Bool Bool -- Bool )
|
|
31
|
+
|
|
32
|
+
# Setoid Unit
|
|
33
|
+
equal = equal_unit
|
|
34
|
+
|
|
35
|
+
: equal_unit ( Unit Unit -- Bool )
|
|
36
|
+
|
|
37
|
+
# Setoid (Array a)
|
|
38
|
+
equal = equal_array
|
|
39
|
+
|
|
40
|
+
: foreign equal_array ( a. Setoid a => (Array a) (Array a) -- Bool )
|
|
41
|
+
|
|
42
|
+
# Setoid Ordering
|
|
43
|
+
equal = equal_ordering
|
|
44
|
+
|
|
45
|
+
: equal_ordering ( Ordering Ordering -- Bool )
|
package/dist/Setoid.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { equal_str, equal_num, equal_int, equal_bool, equal_array } from "../foreign/Setoid.js";
|
|
2
|
+
export { equal_str, equal_num, equal_int, equal_bool, equal_array };
|
|
3
|
+
|
|
4
|
+
export function equal_unit(v0, v1) {
|
|
5
|
+
const v2 = true;
|
|
6
|
+
return v2;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function equal_ordering(v3, v4) {
|
|
10
|
+
let v9;
|
|
11
|
+
if (v3.$$tag === "LT" && v4.$$tag === "LT") {
|
|
12
|
+
const v5 = true;
|
|
13
|
+
v9 = v5;
|
|
14
|
+
} else if (v3.$$tag === "EQ" && v4.$$tag === "EQ") {
|
|
15
|
+
const v6 = true;
|
|
16
|
+
v9 = v6;
|
|
17
|
+
} else if (v3.$$tag === "GT" && v4.$$tag === "GT") {
|
|
18
|
+
const v7 = true;
|
|
19
|
+
v9 = v7;
|
|
20
|
+
} else {
|
|
21
|
+
const v8 = false;
|
|
22
|
+
v9 = v8;
|
|
23
|
+
}
|
|
24
|
+
return v9;
|
|
25
|
+
}
|
package/dist/Show.d.ply
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
language 1
|
|
2
|
+
|
|
3
|
+
@ Show, show
|
|
4
|
+
|
|
5
|
+
~ "Types" Ordering, LT, EQ, GT
|
|
6
|
+
|
|
7
|
+
.. Render a value as text.
|
|
8
|
+
& Show a
|
|
9
|
+
.. The text of this value.
|
|
10
|
+
show ( a -- Str )
|
|
11
|
+
|
|
12
|
+
# Show Str
|
|
13
|
+
show = show_str
|
|
14
|
+
|
|
15
|
+
: foreign show_str ( Str -- Str )
|
|
16
|
+
|
|
17
|
+
# Show Num
|
|
18
|
+
show = show_num
|
|
19
|
+
|
|
20
|
+
: foreign show_num ( Num -- Str )
|
|
21
|
+
|
|
22
|
+
# Show Int
|
|
23
|
+
show = show_int
|
|
24
|
+
|
|
25
|
+
: foreign show_int ( Int -- Str )
|
|
26
|
+
|
|
27
|
+
# Show Bool
|
|
28
|
+
show = show_bool
|
|
29
|
+
|
|
30
|
+
: show_bool ( Bool -- Str )
|
|
31
|
+
|
|
32
|
+
# Show Unit
|
|
33
|
+
show = show_unit
|
|
34
|
+
|
|
35
|
+
: show_unit ( Unit -- Str )
|
|
36
|
+
|
|
37
|
+
# Show (Array a)
|
|
38
|
+
show = show_array
|
|
39
|
+
|
|
40
|
+
: foreign show_array ( Show a => (Array a) -- Str )
|
|
41
|
+
|
|
42
|
+
# Show Ordering
|
|
43
|
+
show = show_ordering
|
|
44
|
+
|
|
45
|
+
: show_ordering ( Ordering -- Str )
|
package/dist/Show.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { show_str, show_num, show_int, show_array } from "../foreign/Show.js";
|
|
2
|
+
export { show_str, show_num, show_int, show_array };
|
|
3
|
+
|
|
4
|
+
export function show_bool(v0) {
|
|
5
|
+
let v3;
|
|
6
|
+
if (v0 === true) {
|
|
7
|
+
const v1 = "True";
|
|
8
|
+
v3 = v1;
|
|
9
|
+
} else {
|
|
10
|
+
const v2 = "False";
|
|
11
|
+
v3 = v2;
|
|
12
|
+
}
|
|
13
|
+
return v3;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function show_unit(v4) {
|
|
17
|
+
const v5 = "Unit";
|
|
18
|
+
return v5;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function show_ordering(v6) {
|
|
22
|
+
let v10;
|
|
23
|
+
if (v6.$$tag === "LT") {
|
|
24
|
+
const v7 = "LT";
|
|
25
|
+
v10 = v7;
|
|
26
|
+
} else if (v6.$$tag === "EQ") {
|
|
27
|
+
const v8 = "EQ";
|
|
28
|
+
v10 = v8;
|
|
29
|
+
} else {
|
|
30
|
+
const v9 = "GT";
|
|
31
|
+
v10 = v9;
|
|
32
|
+
}
|
|
33
|
+
return v10;
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
language 1
|
|
2
|
+
|
|
3
|
+
@ Traversable, traverse, sequence
|
|
4
|
+
|
|
5
|
+
~ "Setoid" equal
|
|
6
|
+
|
|
7
|
+
~ "Foldable" Foldable, size
|
|
8
|
+
|
|
9
|
+
~ "Functor" Functor, map
|
|
10
|
+
|
|
11
|
+
~ "Applicative" Applicative, of
|
|
12
|
+
|
|
13
|
+
~ "Apply" lift2
|
|
14
|
+
|
|
15
|
+
~ "Semigroup" concat
|
|
16
|
+
|
|
17
|
+
~ "Arithmetic" add, sub, div, mod, mult, inc, dec
|
|
18
|
+
|
|
19
|
+
.. Visit each value with a quotation that returns an applicative result, and collect those results in order.
|
|
20
|
+
.. Applicative already brings ap and map.
|
|
21
|
+
& Foldable f, Functor f => Traversable f
|
|
22
|
+
.. Each value visited by a quotation that returns an applicative result. The results stay in order.
|
|
23
|
+
traverse ( Applicative m => (f a) (a -- (m b)) -- (m (f b)) )
|
|
24
|
+
|
|
25
|
+
.. The applicative of the traversable. The inner values stay in order.
|
|
26
|
+
: sequence ( Applicative f => Traversable t => (t (f a)) -- (f (t a)) )
|
|
27
|
+
|
|
28
|
+
# Traversable Array
|
|
29
|
+
traverse = traverseArray
|
|
30
|
+
|
|
31
|
+
: traverseArray ( f a b. Applicative f => (Array a) (a -- (f b)) -- (f (Array b)) )
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { size, fold_array } from "./Foldable.js";
|
|
2
|
+
import { lift2 } from "./Apply.js";
|
|
3
|
+
import { inc, dec, add_num, div_num, mod_num, mult_num, negate_num, one_num, sub_num, zero_num } from "./Arithmetic.js";
|
|
4
|
+
import { concat_array } from "./Semigroup.js";
|
|
5
|
+
import { equal_num } from "./Setoid.js";
|
|
6
|
+
import { of_array } from "./Applicative.js";
|
|
7
|
+
import { index_array } from "../foreign/Traversable.js";
|
|
8
|
+
|
|
9
|
+
const v10 = ({ fold: fold_array });
|
|
10
|
+
const v95 = ({ add: add_num, sub: sub_num, mult: mult_num, div: div_num, mod: mod_num, negate: negate_num, zero: zero_num, one: one_num });
|
|
11
|
+
|
|
12
|
+
export function sequence(v0, v1, v2) {
|
|
13
|
+
const v4 = (v3) => v3;
|
|
14
|
+
const v5 = v1.traverse;
|
|
15
|
+
const v6 = v5(v0, v2, v4);
|
|
16
|
+
return v6;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function traverseArray(v7, v8, v9) {
|
|
20
|
+
const v11 = size(v10, v8);
|
|
21
|
+
const v12 = 2;
|
|
22
|
+
const v13 = mod_num(v11, v12);
|
|
23
|
+
const v14 = 0;
|
|
24
|
+
const v15 = equal_num(v13, v14);
|
|
25
|
+
let v31;
|
|
26
|
+
if (v15) {
|
|
27
|
+
const v28 = 0;
|
|
28
|
+
const v29 = go(v7, v8, v9, v28, v11);
|
|
29
|
+
v31 = v29;
|
|
30
|
+
} else {
|
|
31
|
+
const v30 = evenTraverse(v7, v8, v9, v11);
|
|
32
|
+
v31 = v30;
|
|
33
|
+
}
|
|
34
|
+
return v31;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function pair(v32, v33) {
|
|
38
|
+
let v35;
|
|
39
|
+
const v34 = [v32, v33];
|
|
40
|
+
v35 = v34;
|
|
41
|
+
return v35;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function evenTraverse(v91, v92, v93, v94) {
|
|
45
|
+
const v96 = dec(v95, v94);
|
|
46
|
+
const v97 = 1;
|
|
47
|
+
const v100 = go(v91, v92, v93, v97, v96);
|
|
48
|
+
const v129 = 0;
|
|
49
|
+
const v130 = index_array(v92, v129);
|
|
50
|
+
const v131 = v93(v130);
|
|
51
|
+
const v132 = (v133) => {
|
|
52
|
+
const v134 = of_array(v133);
|
|
53
|
+
return v134;
|
|
54
|
+
};
|
|
55
|
+
const v135 = v91.Apply;
|
|
56
|
+
const v136 = v135.Functor;
|
|
57
|
+
const v137 = v136.map;
|
|
58
|
+
const v138 = v137(v131, v132);
|
|
59
|
+
const v143 = (v139, v140) => {
|
|
60
|
+
const v142 = concat_array(v139, v140);
|
|
61
|
+
return v142;
|
|
62
|
+
};
|
|
63
|
+
const v144 = v91.Apply;
|
|
64
|
+
const v145 = lift2(v144, v138, v100, v143);
|
|
65
|
+
return v145;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function go(v156, v157, v158, v159, v160) {
|
|
69
|
+
let v166;
|
|
70
|
+
if (v160 === 0) {
|
|
71
|
+
const v161 = [];
|
|
72
|
+
const v162 = v156.of;
|
|
73
|
+
const v163 = v162(v161);
|
|
74
|
+
v166 = v163;
|
|
75
|
+
} else if (v160 === 2) {
|
|
76
|
+
const v164 = go2(v156, v157, v158, v159);
|
|
77
|
+
v166 = v164;
|
|
78
|
+
} else {
|
|
79
|
+
const v165 = goDefault(v156, v157, v158, v159, v160);
|
|
80
|
+
v166 = v165;
|
|
81
|
+
}
|
|
82
|
+
return v166;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function go2(v167, v168, v169, v170) {
|
|
86
|
+
const v176 = index_array(v168, v170);
|
|
87
|
+
const v177 = inc(v95, v170);
|
|
88
|
+
const v178 = index_array(v168, v177);
|
|
89
|
+
const v179 = v169(v176);
|
|
90
|
+
const v180 = v169(v178);
|
|
91
|
+
const v185 = (v181, v182) => {
|
|
92
|
+
const v184 = pair(v181, v182);
|
|
93
|
+
return v184;
|
|
94
|
+
};
|
|
95
|
+
const v186 = v167.Apply;
|
|
96
|
+
const v187 = lift2(v186, v179, v180, v185);
|
|
97
|
+
return v187;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function goDefault(v224, v225, v226, v227, v228) {
|
|
101
|
+
const v229 = 4;
|
|
102
|
+
const v230 = div_num(v228, v229);
|
|
103
|
+
const v231 = 2;
|
|
104
|
+
const v232 = mult_num(v230, v231);
|
|
105
|
+
const v240 = leftGo(v224, v227, v232);
|
|
106
|
+
const v245 = rigthGo(v224, v228, v227, v232);
|
|
107
|
+
const v251 = v240(v225, v226);
|
|
108
|
+
const v252 = v245(v225, v226);
|
|
109
|
+
const v257 = (v253, v254) => {
|
|
110
|
+
const v256 = concat_array(v253, v254);
|
|
111
|
+
return v256;
|
|
112
|
+
};
|
|
113
|
+
const v258 = v224.Apply;
|
|
114
|
+
const v259 = lift2(v258, v251, v252, v257);
|
|
115
|
+
return v259;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function leftGo(v260, v261, v262) {
|
|
119
|
+
const v269 = (v263, v264) => {
|
|
120
|
+
const v268 = go(v260, v263, v264, v261, v262);
|
|
121
|
+
return v268;
|
|
122
|
+
};
|
|
123
|
+
return v269;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function rigthGo(v270, v271, v272, v273) {
|
|
127
|
+
const v279 = add_num(v272, v273);
|
|
128
|
+
const v280 = sub_num(v271, v273);
|
|
129
|
+
const v287 = (v281, v282) => {
|
|
130
|
+
const v286 = go(v270, v281, v282, v279, v280);
|
|
131
|
+
return v286;
|
|
132
|
+
};
|
|
133
|
+
return v287;
|
|
134
|
+
}
|
package/dist/Types.d.ply
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
language 1
|
|
2
|
+
|
|
3
|
+
@ Ordering, LT, EQ, GT
|
|
4
|
+
|
|
5
|
+
# Nullary Str
|
|
6
|
+
checkNullary = is_str
|
|
7
|
+
|
|
8
|
+
: foreign is_str ( a -- Bool )
|
|
9
|
+
|
|
10
|
+
# Nullary Num
|
|
11
|
+
checkNullary = is_num
|
|
12
|
+
|
|
13
|
+
: foreign is_num ( a -- Bool )
|
|
14
|
+
|
|
15
|
+
# Nullary Int
|
|
16
|
+
checkNullary = is_int
|
|
17
|
+
|
|
18
|
+
: foreign is_int ( a -- Bool )
|
|
19
|
+
|
|
20
|
+
# Nullary Bool
|
|
21
|
+
checkNullary = is_bool
|
|
22
|
+
|
|
23
|
+
: foreign is_bool ( a -- Bool )
|
|
24
|
+
|
|
25
|
+
# Nullary Unit
|
|
26
|
+
checkNullary = is_unit
|
|
27
|
+
|
|
28
|
+
: foreign is_unit ( a -- Bool )
|
|
29
|
+
|
|
30
|
+
# Unary Array
|
|
31
|
+
checkUnary = is_array
|
|
32
|
+
checkUnary_1 = is_array_1
|
|
33
|
+
|
|
34
|
+
: foreign is_array ( b -- Bool )
|
|
35
|
+
|
|
36
|
+
: foreign is_array_1 ( (Array a) (a -- Bool) -- Bool )
|
|
37
|
+
|
|
38
|
+
.. LT is below EQ. EQ is below GT.
|
|
39
|
+
; Ordering = LT | EQ | GT
|
package/dist/Types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { is_str, is_num, is_int, is_bool, is_unit, is_array, is_array_1 } from "../foreign/Types.js";
|
|
2
|
+
export { is_str, is_num, is_int, is_bool, is_unit, is_array, is_array_1 };
|
|
3
|
+
|
|
4
|
+
export const LT = { $$tag: "LT" };
|
|
5
|
+
|
|
6
|
+
export const EQ = { $$tag: "EQ" };
|
|
7
|
+
|
|
8
|
+
export const GT = { $$tag: "GT" };
|
package/foreign/Alt.js
ADDED
package/foreign/Apply.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function add_int(a, b) {
|
|
2
|
+
return a + b
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function sub_int(a, b) {
|
|
6
|
+
return a - b
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function mult_int(a, b) {
|
|
10
|
+
return a * b
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function div_int(a, b) {
|
|
14
|
+
if (b === 0n) throw new Error('division by zero')
|
|
15
|
+
return a / b
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function mod_int(a, b) {
|
|
19
|
+
if (b === 0n) throw new Error('division by zero')
|
|
20
|
+
return a % b
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function negate_int(a) {
|
|
24
|
+
return -a
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function add_num(a, b) {
|
|
28
|
+
return a + b
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function sub_num(a, b) {
|
|
32
|
+
return a - b
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function mult_num(a, b) {
|
|
36
|
+
return a * b
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function div_num(a, b) {
|
|
40
|
+
const quotient = Math.floor(a / b)
|
|
41
|
+
if (b === 0 || !Number.isFinite(quotient)) {
|
|
42
|
+
throw new Error('division by zero')
|
|
43
|
+
}
|
|
44
|
+
return quotient
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function mod_num(a, b) {
|
|
48
|
+
const remainder = a % b
|
|
49
|
+
if (b === 0 || !Number.isFinite(remainder)) {
|
|
50
|
+
throw new Error('division by zero')
|
|
51
|
+
}
|
|
52
|
+
return remainder
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function negate_num(a) {
|
|
56
|
+
return -a
|
|
57
|
+
}
|
package/foreign/Chain.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function filter_array(xs, f) {
|
|
2
|
+
return xs.filter((x) => f(x))
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function partition_array(xs, pred) {
|
|
6
|
+
const matches = []
|
|
7
|
+
const rest = []
|
|
8
|
+
for (let i = 0; i < xs.length; i += 1) {
|
|
9
|
+
if (pred(xs[i])) matches.push(xs[i])
|
|
10
|
+
else rest.push(xs[i])
|
|
11
|
+
}
|
|
12
|
+
return [matches, rest]
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function fold_array(xs, init, f) {
|
|
2
|
+
let acc = init
|
|
3
|
+
for (const x of xs) acc = f(acc, x)
|
|
4
|
+
return acc
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function size_array(xs) {
|
|
8
|
+
return xs.length
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function all_array(xs, pred) {
|
|
12
|
+
return xs.every(pred)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function any_array(xs, pred) {
|
|
16
|
+
return xs.some(pred)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function reverse_array(xs) {
|
|
20
|
+
return xs.slice().reverse()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function sort_array(xs, pred) {
|
|
24
|
+
return xs.concat([]).sort(pred)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function length_str(str) {
|
|
28
|
+
return str.length
|
|
29
|
+
}
|
package/foreign/Ord.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function lte_str(a, b) {
|
|
2
|
+
return a <= b
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function lte_num(a, b) {
|
|
6
|
+
return a <= b
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function lte_int(a, b) {
|
|
10
|
+
return a <= b
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function lte_bool(a, b) {
|
|
14
|
+
return a === false || b === true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function lte_unit(a, b) {
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function lte_array(ord, xs, ys) {
|
|
22
|
+
const lte = ord.lte
|
|
23
|
+
const equal = ord.Setoid.equal
|
|
24
|
+
|
|
25
|
+
for (let idx = 0; true; idx += 1) {
|
|
26
|
+
if (idx === xs.length) break
|
|
27
|
+
if (idx === ys.length) return false
|
|
28
|
+
if (!equal(xs[idx], ys[idx])) {
|
|
29
|
+
return lte(xs[idx], ys[idx])
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function equal_str(a, b) {
|
|
2
|
+
return a === b
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function equal_num(a, b) {
|
|
6
|
+
return a === b
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function equal_int(a, b) {
|
|
10
|
+
return a === b
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function equal_bool(a, b) {
|
|
14
|
+
return a === b
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function equal_array(eq, xs, ys) {
|
|
18
|
+
if (xs.length !== ys.length) return false
|
|
19
|
+
const equal = eq.equal
|
|
20
|
+
for (let i = 0; i < xs.length; i += 1) {
|
|
21
|
+
if (!equal(xs[i], ys[i])) return false
|
|
22
|
+
}
|
|
23
|
+
return true
|
|
24
|
+
}
|
package/foreign/Show.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function show_str(value) {
|
|
2
|
+
return JSON.stringify(value)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function show_num(a) {
|
|
6
|
+
if (Number.isNaN(a)) return 'NaN'
|
|
7
|
+
if (a === Infinity) return 'Infinity'
|
|
8
|
+
if (a === -Infinity) return '-Infinity'
|
|
9
|
+
return String(a)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function show_int(a) {
|
|
13
|
+
return a.toString() + 'n'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function show_array(Show, xs) {
|
|
17
|
+
const show = Show.show
|
|
18
|
+
|
|
19
|
+
return '< ' + xs.map(show).join(' ') + ' >'
|
|
20
|
+
}
|
package/foreign/Types.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const Cell_Symbol = Symbol('Cell')
|
|
2
|
+
|
|
3
|
+
export function is_str(value) {
|
|
4
|
+
return typeof value === 'string'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function is_num(value) {
|
|
8
|
+
return typeof value === 'number'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function is_int(value) {
|
|
12
|
+
return typeof value === 'bigint'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function is_bool(value) {
|
|
16
|
+
return typeof value === 'boolean'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function is_unit(value) {
|
|
20
|
+
return value === undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function is_array(value) {
|
|
24
|
+
return Array.isArray(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function is_array_1(xs, pred) {
|
|
28
|
+
for (let i = 0; i < xs.length; i += 1) {
|
|
29
|
+
if (!pred(xs[i])) return false
|
|
30
|
+
}
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function is_strMap(value) {
|
|
35
|
+
typeof value === 'object'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function is_strMap_1(xs, pred) {
|
|
39
|
+
for (const v of Object.values(xs)) {
|
|
40
|
+
if (!pred(v)) return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function is_cell(value) {
|
|
47
|
+
return value?.$$type === Cell_Symbol
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function is_cell_1(value, pred) {
|
|
51
|
+
return pred(value.$$type)
|
|
52
|
+
}
|