@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.
Files changed (61) hide show
  1. package/README.md +1679 -2
  2. package/dist/Alt.d.ply +16 -0
  3. package/dist/Alt.js +2 -0
  4. package/dist/Alternative.d.ply +13 -0
  5. package/dist/Alternative.js +16 -0
  6. package/dist/Applicative.d.ply +23 -0
  7. package/dist/Applicative.js +18 -0
  8. package/dist/Apply.d.ply +31 -0
  9. package/dist/Apply.js +37 -0
  10. package/dist/Arithmetic.d.ply +83 -0
  11. package/dist/Arithmetic.js +54 -0
  12. package/dist/Bifunctor.d.ply +12 -0
  13. package/dist/Bifunctor.js +13 -0
  14. package/dist/Chain.d.ply +22 -0
  15. package/dist/Chain.js +9 -0
  16. package/dist/Composition.d.ply +16 -0
  17. package/dist/Composition.js +38 -0
  18. package/dist/Filterable.d.ply +28 -0
  19. package/dist/Filterable.js +14 -0
  20. package/dist/Foldable.d.ply +63 -0
  21. package/dist/Foldable.js +238 -0
  22. package/dist/Functor.d.ply +17 -0
  23. package/dist/Functor.js +12 -0
  24. package/dist/Group.d.ply +10 -0
  25. package/dist/Logical.d.ply +37 -0
  26. package/dist/Logical.js +20 -0
  27. package/dist/Monad.d.ply +10 -0
  28. package/dist/Monoid.d.ply +32 -0
  29. package/dist/Monoid.js +21 -0
  30. package/dist/Ord.d.ply +67 -0
  31. package/dist/Ord.js +106 -0
  32. package/dist/Plus.d.ply +16 -0
  33. package/dist/Plus.js +13 -0
  34. package/dist/Prelude.d.ply +47 -0
  35. package/dist/Prelude.js +15 -0
  36. package/dist/Semigroup.d.ply +30 -0
  37. package/dist/Semigroup.js +19 -0
  38. package/dist/Setoid.d.ply +45 -0
  39. package/dist/Setoid.js +25 -0
  40. package/dist/Show.d.ply +45 -0
  41. package/dist/Show.js +34 -0
  42. package/dist/Traversable.d.ply +31 -0
  43. package/dist/Traversable.js +134 -0
  44. package/dist/Types.d.ply +39 -0
  45. package/dist/Types.js +8 -0
  46. package/foreign/Alt.js +3 -0
  47. package/foreign/Applicative.js +3 -0
  48. package/foreign/Apply.js +9 -0
  49. package/foreign/Arithmetic.js +57 -0
  50. package/foreign/Chain.js +9 -0
  51. package/foreign/Filterable.js +13 -0
  52. package/foreign/Foldable.js +29 -0
  53. package/foreign/Functor.js +3 -0
  54. package/foreign/Logical.js +11 -0
  55. package/foreign/Ord.js +34 -0
  56. package/foreign/Semigroup.js +7 -0
  57. package/foreign/Setoid.js +24 -0
  58. package/foreign/Show.js +20 -0
  59. package/foreign/Traversable.js +3 -0
  60. package/foreign/Types.js +52 -0
  61. package/package.json +131 -4
package/dist/Alt.d.ply ADDED
@@ -0,0 +1,16 @@
1
+ language 1
2
+
3
+ @ Alt, alt
4
+
5
+ ~ "Functor" Functor
6
+
7
+ .. Keep the lower value when it is a result, otherwise the upper one.
8
+ .. An array keeps both, lower first.
9
+ & Functor f => Alt f
10
+ .. The lower value when it is a result, otherwise the upper one.
11
+ alt ( (f a) (f a) -- (f a) )
12
+
13
+ # Alt Array
14
+ alt = alt_array
15
+
16
+ : foreign alt_array ( (Array a) (Array a) -- (Array a) )
package/dist/Alt.js ADDED
@@ -0,0 +1,2 @@
1
+ import { alt_array } from "../foreign/Alt.js";
2
+ export { alt_array };
@@ -0,0 +1,13 @@
1
+ language 1
2
+
3
+ @ Alternative, guard
4
+
5
+ ~ "Applicative" Applicative, of
6
+
7
+ ~ "Plus" Plus, init
8
+
9
+ .. One constraint brings of, alt, and zero.
10
+ & Applicative f, Plus f => Alternative f
11
+
12
+ .. true is of Unit. false is zero.
13
+ : guard ( Alternative f => Bool -- (f Unit) )
@@ -0,0 +1,16 @@
1
+ export function guard(v12, v13) {
2
+ let v35;
3
+ if (v13) {
4
+ const v28 = undefined;
5
+ const v29 = v12.Applicative;
6
+ const v30 = v29.of;
7
+ const v31 = v30(v28);
8
+ v35 = v31;
9
+ } else {
10
+ const v32 = v12.Plus;
11
+ const v33 = v32.init;
12
+ const v34 = v33();
13
+ v35 = v34;
14
+ }
15
+ return v35;
16
+ }
@@ -0,0 +1,23 @@
1
+ language 1
2
+
3
+ @ Applicative, of, append, prepend
4
+
5
+ ~ "Apply" Apply
6
+
7
+ ~ "Semigroup" Semigroup, concat
8
+
9
+ .. Put one value into the container.
10
+ & Apply f => Applicative f
11
+ .. The container of this one value.
12
+ of ( a -- (f a) )
13
+
14
+ .. The container with this value joined after it.
15
+ : append ( Applicative f => Semigroup (f a) => (f a) a -- (f a) )
16
+
17
+ .. The container with this value joined before it.
18
+ : prepend ( Applicative f => Semigroup (f a) => (f a) a -- (f a) )
19
+
20
+ # Applicative Array
21
+ of = of_array
22
+
23
+ : foreign of_array ( a -- (Array a) )
@@ -0,0 +1,18 @@
1
+ import { of_array } from "../foreign/Applicative.js";
2
+ export { of_array };
3
+
4
+ export function append(v7, v8, v9, v10) {
5
+ const v11 = v7.of;
6
+ const v12 = v11(v10);
7
+ const v13 = v8.concat;
8
+ const v14 = v13(v9, v12);
9
+ return v14;
10
+ }
11
+
12
+ export function prepend(v22, v23, v24, v25) {
13
+ const v26 = v22.of;
14
+ const v27 = v26(v25);
15
+ const v28 = v23.concat;
16
+ const v29 = v28(v27, v24);
17
+ return v29;
18
+ }
@@ -0,0 +1,31 @@
1
+ language 1
2
+
3
+ @ Apply, ap, lift2, lift3, apFirst, apSecond
4
+
5
+ ~ "Functor" Functor, map
6
+
7
+ ~ "Composition" curry2, curry3
8
+
9
+ .. Apply a container of quotations. The quotations are on top.
10
+ & Functor f => Apply f
11
+ .. Each value run with the quotation beside it. The quotations are on top.
12
+ ap ( (f a) (f (a -- b)) -- (f b) )
13
+
14
+ .. Pass two container values, from the bottom upward, to one quotation.
15
+ .. map takes the lower value. ap takes the upper one. The quotation stays uncurried.
16
+ : lift2 ( Apply f => (f a) (f b) (a b -- c) -- (f c) )
17
+
18
+ .. Pass three container values, from the bottom upward, to one quotation.
19
+ .. map takes the first value. ap takes the other two. The quotation stays uncurried.
20
+ : lift3 ( Apply f => (f a) (f b) (f c) (a b c -- d) -- (f d) )
21
+
22
+ .. Keep the lower container's value. The upper container still runs.
23
+ : apFirst ( Apply f => (f a) (f b) -- (f a) )
24
+
25
+ .. Keep the upper container's value. The lower container still runs.
26
+ : apSecond ( Apply f => (f a) (f b) -- (f b) )
27
+
28
+ # Apply Array
29
+ ap = ap_array
30
+
31
+ : foreign ap_array ( (Array a) (Array (a -- b)) -- (Array b) )
package/dist/Apply.js ADDED
@@ -0,0 +1,37 @@
1
+ import { curry2, curry3 } from "./Composition.js";
2
+ import { ap_array } from "../foreign/Apply.js";
3
+ export { ap_array };
4
+
5
+ export function lift2(v0, v1, v2, v3) {
6
+ const v4 = curry2(v3);
7
+ const v5 = v0.Functor;
8
+ const v6 = v5.map;
9
+ const v7 = v6(v1, v4);
10
+ const v8 = v0.ap;
11
+ const v9 = v8(v2, v7);
12
+ return v9;
13
+ }
14
+
15
+ export function lift3(v10, v11, v12, v13, v14) {
16
+ const v18 = curry3(v14);
17
+ const v19 = v10.Functor;
18
+ const v20 = v19.map;
19
+ const v21 = v20(v11, v18);
20
+ const v22 = v10.ap;
21
+ const v23 = v22(v12, v21);
22
+ const v24 = v10.ap;
23
+ const v25 = v24(v13, v23);
24
+ return v25;
25
+ }
26
+
27
+ export function apFirst(v26, v27, v28) {
28
+ const v31 = (v29, v30) => v29;
29
+ const v32 = lift2(v26, v27, v28, v31);
30
+ return v32;
31
+ }
32
+
33
+ export function apSecond(v33, v34, v35) {
34
+ const v38 = (v36, v37) => v37;
35
+ const v39 = lift2(v33, v34, v35, v38);
36
+ return v39;
37
+ }
@@ -0,0 +1,83 @@
1
+ language 1
2
+
3
+ @ Arithmetic, add, sub, mult, div, mod, negate, zero, one, inc, dec, abs
4
+
5
+ ~ "Ord" Ord, lt
6
+
7
+ .. Arithmetic methods share one instance.
8
+ & Arithmetic a
9
+ .. The lower value plus the upper one.
10
+ add ( a a -- a )
11
+ .. The upper value subtracted from the lower one.
12
+ sub ( a a -- a )
13
+ .. The lower value times the upper one.
14
+ mult ( a a -- a )
15
+ .. The lower value divided by the upper one. A zero divisor throws.
16
+ div ( a a -- a )
17
+ .. The remainder. A zero divisor throws.
18
+ mod ( a a -- a )
19
+ .. The sign flipped.
20
+ negate ( a -- a )
21
+ .. The value add leaves unchanged.
22
+ zero ( -- a )
23
+ .. The value multiply leaves unchanged.
24
+ one ( -- a )
25
+
26
+ : inc ( Arithmetic a => a -- a )
27
+
28
+ : dec ( Arithmetic a => a -- a )
29
+
30
+ .. The value with a negative sign flipped. NaN stays NaN, and -0 stays -0.
31
+ : abs ( Arithmetic a => Ord a => a -- a )
32
+
33
+ # Arithmetic Int
34
+ add = add_int
35
+ sub = sub_int
36
+ mult = mult_int
37
+ div = div_int
38
+ mod = mod_int
39
+ negate = negate_int
40
+ zero = zero_int
41
+ one = one_int
42
+
43
+ : foreign add_int ( Int Int -- Int )
44
+
45
+ : foreign sub_int ( Int Int -- Int )
46
+
47
+ : foreign mult_int ( Int Int -- Int )
48
+
49
+ : foreign div_int ( Int Int -- Int )
50
+
51
+ : foreign mod_int ( Int Int -- Int )
52
+
53
+ : foreign negate_int ( Int -- Int )
54
+
55
+ : zero_int ( -- Int )
56
+
57
+ : one_int ( -- Int )
58
+
59
+ # Arithmetic Num
60
+ add = add_num
61
+ sub = sub_num
62
+ mult = mult_num
63
+ div = div_num
64
+ mod = mod_num
65
+ negate = negate_num
66
+ zero = zero_num
67
+ one = one_num
68
+
69
+ : foreign add_num ( Num Num -- Num )
70
+
71
+ : foreign sub_num ( Num Num -- Num )
72
+
73
+ : foreign mult_num ( Num Num -- Num )
74
+
75
+ : foreign div_num ( Num Num -- Num )
76
+
77
+ : foreign mod_num ( Num Num -- Num )
78
+
79
+ : foreign negate_num ( Num -- Num )
80
+
81
+ : zero_num ( -- Num )
82
+
83
+ : one_num ( -- Num )
@@ -0,0 +1,54 @@
1
+ import { lt } from "./Ord.js";
2
+ import { add_int, sub_int, mult_int, div_int, mod_int, negate_int, add_num, sub_num, mult_num, div_num, mod_num, negate_num } from "../foreign/Arithmetic.js";
3
+ export { add_int, sub_int, mult_int, div_int, mod_int, negate_int, add_num, sub_num, mult_num, div_num, mod_num, negate_num };
4
+
5
+ export function inc(v5, v6) {
6
+ const v7 = v5.one;
7
+ const v8 = v7();
8
+ const v9 = v5.add;
9
+ const v10 = v9(v6, v8);
10
+ return v10;
11
+ }
12
+
13
+ export function dec(v16, v17) {
14
+ const v18 = v16.one;
15
+ const v19 = v18();
16
+ const v20 = v16.sub;
17
+ const v21 = v20(v17, v19);
18
+ return v21;
19
+ }
20
+
21
+ export function abs(v36, v37, v38) {
22
+ const v39 = v36.zero;
23
+ const v40 = v39();
24
+ const v41 = lt(v37, v38, v40);
25
+ let v50;
26
+ if (v41) {
27
+ const v48 = v36.negate;
28
+ const v49 = v48(v38);
29
+ v50 = v49;
30
+ } else {
31
+ v50 = v38;
32
+ }
33
+ return v50;
34
+ }
35
+
36
+ export function zero_int() {
37
+ const v51 = 0n;
38
+ return v51;
39
+ }
40
+
41
+ export function one_int() {
42
+ const v52 = 1n;
43
+ return v52;
44
+ }
45
+
46
+ export function zero_num() {
47
+ const v53 = 0;
48
+ return v53;
49
+ }
50
+
51
+ export function one_num() {
52
+ const v54 = 1;
53
+ return v54;
54
+ }
@@ -0,0 +1,12 @@
1
+ language 1
2
+
3
+ @ Bifunctor, bimap, mapLeft, mapRight
4
+
5
+ .. Map both parameters. The left quotation is under the right one.
6
+ & Bifunctor f
7
+ .. Left quotation under the right one.
8
+ bimap ( (f a c) (a -- b) (c -- d) -- (f b d) )
9
+
10
+ : mapLeft ( Bifunctor f => (f a c) (a -- b) -- (f b c) )
11
+
12
+ : mapRight ( Bifunctor f => (f a c) (c -- b) -- (f a b) )
@@ -0,0 +1,13 @@
1
+ export function mapLeft(v0, v1, v2) {
2
+ const v4 = (v3) => v3;
3
+ const v5 = v0.bimap;
4
+ const v6 = v5(v1, v2, v4);
5
+ return v6;
6
+ }
7
+
8
+ export function mapRight(v7, v8, v9) {
9
+ const v11 = (v10) => v10;
10
+ const v12 = v7.bimap;
11
+ const v13 = v12(v8, v11, v9);
12
+ return v13;
13
+ }
@@ -0,0 +1,22 @@
1
+ language 1
2
+
3
+ @ Chain, chain, join
4
+
5
+ ~ "Apply" Apply
6
+
7
+ ~ "Applicative" append
8
+
9
+ ~ "Arithmetic" mult
10
+
11
+ .. Apply a quotation that returns a container, and join the results. The quotation is on top.
12
+ & Apply f => Chain f
13
+ .. The containers the quotation returns, joined into one.
14
+ chain ( (f a) (a -- (f b)) -- (f b) )
15
+
16
+ .. One layer removed. The inner container is the result.
17
+ : join ( Chain f => (f (f a)) -- (f a) )
18
+
19
+ # Chain Array
20
+ chain = chain_array
21
+
22
+ : foreign chain_array ( (Array a) (a -- (Array b)) -- (Array b) )
package/dist/Chain.js ADDED
@@ -0,0 +1,9 @@
1
+ import { chain_array } from "../foreign/Chain.js";
2
+ export { chain_array };
3
+
4
+ export function join(v0, v1) {
5
+ const v3 = (v2) => v2;
6
+ const v4 = v0.chain;
7
+ const v5 = v4(v1, v3);
8
+ return v5;
9
+ }
@@ -0,0 +1,16 @@
1
+ language 1
2
+
3
+ @ compose, id, curry2, curry3
4
+
5
+ .. Runs the lower quotation first and the upper one second.
6
+ .. A function type cannot be an instance head, so composition is a pair of words.
7
+ : compose ( (a -- b) (b -- c) -- (a -- c) )
8
+
9
+ .. A quotation that returns its input.
10
+ : id ( -- (a -- a) )
11
+
12
+ .. Split a binary quotation into unary steps, so ap can take one value at a time.
13
+ : curry2 ( (a b -- c) -- (a -- (b -- c)) )
14
+
15
+ .. Split a ternary quotation into unary steps, so ap can take one value at a time.
16
+ : curry3 ( (a b c -- d) -- (a -- (b -- (c -- d))) )
@@ -0,0 +1,38 @@
1
+ export function compose(v0, v1) {
2
+ const v13 = (v2) => {
3
+ const v11 = v0(v2);
4
+ const v12 = v1(v11);
5
+ return v12;
6
+ };
7
+ return v13;
8
+ }
9
+
10
+ export function id() {
11
+ const v15 = (v14) => v14;
12
+ return v15;
13
+ }
14
+
15
+ export function curry2(v16) {
16
+ const v28 = (v17) => {
17
+ const v25 = (v26) => {
18
+ const v27 = v16(v17, v26);
19
+ return v27;
20
+ };
21
+ return v25;
22
+ };
23
+ return v28;
24
+ }
25
+
26
+ export function curry3(v29) {
27
+ const v54 = (v30) => {
28
+ const v49 = (v50) => {
29
+ const v51 = (v52) => {
30
+ const v53 = v29(v30, v50, v52);
31
+ return v53;
32
+ };
33
+ return v51;
34
+ };
35
+ return v49;
36
+ };
37
+ return v54;
38
+ }
@@ -0,0 +1,28 @@
1
+ language 1
2
+
3
+ @ Filterable, filter, partition, reject
4
+
5
+ ~ "Logical" not
6
+
7
+ ~ "Setoid" equal
8
+
9
+ ~ "Ord" lt
10
+
11
+ .. filter keeps values the quotation accepts.
12
+ .. partition leaves the matches below and the rest on top.
13
+ .. filterMap keeps Some. partitionMap leaves Right below and Left on top.
14
+ & Filterable f
15
+ .. Values the quotation accepts.
16
+ filter ( (f a) (a -- Bool) -- (f a) )
17
+ .. Matches below, the rest on top.
18
+ partition ( (f a) (a -- Bool) -- (f a) (f a) )
19
+
20
+ : reject ( Filterable f => (f a) (a -- Bool) -- (f a) )
21
+
22
+ # Filterable Array
23
+ filter = filter_array
24
+ partition = partition_array
25
+
26
+ : foreign filter_array ( a. (Array a) (a -- Bool) -- (Array a) )
27
+
28
+ : foreign partition_array ( a. (Array a) (a -- Bool) -- (Array a) (Array a) )
@@ -0,0 +1,14 @@
1
+ import { not_bool } from "./Logical.js";
2
+ import { filter_array, partition_array } from "../foreign/Filterable.js";
3
+ export { filter_array, partition_array };
4
+
5
+ export function reject(v0, v1, v2) {
6
+ const v9 = (v3) => {
7
+ const v7 = v2(v3);
8
+ const v8 = not_bool(v7);
9
+ return v8;
10
+ };
11
+ const v10 = v0.filter;
12
+ const v11 = v10(v1, v9);
13
+ return v11;
14
+ }
@@ -0,0 +1,63 @@
1
+ language 1
2
+
3
+ @ Foldable, fold, size, all, any, none, elem, intercalate, foldMap, reverse, sortBy, sort
4
+
5
+ ~ "Setoid" Setoid, equal
6
+
7
+ ~ "Monoid" Monoid, empty
8
+
9
+ ~ "Applicative" Applicative, append, prepend
10
+
11
+ ~ "Ord" Ord, lt, lte
12
+
13
+ ~ "Arithmetic" add, sub, inc
14
+
15
+ ~ "Logical" and, or, not
16
+
17
+ ~ "Semigroup" concat
18
+
19
+ ~ "Filterable" filter
20
+
21
+ .. fold walks from the left. The initial value sits under the quotation.
22
+ .. size, all, any, none, elem, intercalate, foldMap and reverse are in Words/Fold.
23
+ .. sort and sortBy are in Words/Sort.
24
+ .. size counts with Num. Importing Num here cycles through Option.
25
+ & Foldable f
26
+ .. Walk from the left. The initial value sits under the quotation.
27
+ fold ( (f a) b (b a -- b) -- b )
28
+
29
+ .. How many elements. An empty structure is 0.
30
+ : size ( Foldable f => (f a) -- Num )
31
+
32
+ .. True when every element suits the quotation. An empty structure is true.
33
+ : all ( Foldable f => (f a) (a -- Bool) -- Bool )
34
+
35
+ .. True when one element suits the quotation. An empty structure is false.
36
+ : any ( Foldable f => (f a) (a -- Bool) -- Bool )
37
+
38
+ .. True when no element suits the quotation. An empty structure is true.
39
+ : none ( Foldable f => (f a) (a -- Bool) -- Bool )
40
+
41
+ .. True when the upper value equals some element.
42
+ : elem ( Setoid a => Foldable f => (f a) a -- Bool )
43
+
44
+ .. The pieces joined, with the separator between them. An empty structure is empty.
45
+ : intercalate ( Monoid m => Foldable f => (f m) m -- m )
46
+
47
+ .. Concat each result, starting from empty.
48
+ : foldMap ( Monoid m => Foldable f => (f a) (a -- m) -- m )
49
+
50
+ .. The elements in the opposite order.
51
+ : reverse ( Applicative f => Foldable f => Monoid (f a) => (f a) -- (f a) )
52
+
53
+ .. The elements ordered by the quotation, using lte on each result.
54
+ .. An equal result keeps the earlier element.
55
+ : sortBy ( Ord b => Applicative f => Foldable f => Monoid (f a) => (f a) (a -- b) -- (f a) )
56
+
57
+ .. The elements ordered by lte. An equal element keeps the earlier place.
58
+ : sort ( Ord a => Applicative f => Foldable f => Monoid (f a) => (f a) -- (f a) )
59
+
60
+ # Foldable Array
61
+ fold = fold_array
62
+
63
+ : foreign fold_array ( a b. (Array a) b (b a -- b) -- b )