@plylang/prelude 1.0.0 → 1.1.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 CHANGED
@@ -4,20 +4,22 @@
4
4
  - [@plylang/prelude/Alternative](#plylangpreludealternative)
5
5
  - [@plylang/prelude/Applicative](#plylangpreludeapplicative)
6
6
  - [@plylang/prelude/Apply](#plylangpreludeapply)
7
- - [@plylang/prelude/Arithmetic](#plylangpreludearithmetic)
8
7
  - [@plylang/prelude/Bifunctor](#plylangpreludebifunctor)
9
8
  - [@plylang/prelude/Chain](#plylangpreludechain)
10
9
  - [@plylang/prelude/Composition](#plylangpreludecomposition)
11
10
  - [@plylang/prelude/Filterable](#plylangpreludefilterable)
12
11
  - [@plylang/prelude/Foldable](#plylangpreludefoldable)
12
+ - [@plylang/prelude/Fractional](#plylangpreludefractional)
13
13
  - [@plylang/prelude/Functor](#plylangpreludefunctor)
14
14
  - [@plylang/prelude/Group](#plylangpreludegroup)
15
15
  - [@plylang/prelude/Logical](#plylangpreludelogical)
16
16
  - [@plylang/prelude/Monad](#plylangpreludemonad)
17
17
  - [@plylang/prelude/Monoid](#plylangpreludemonoid)
18
+ - [@plylang/prelude/Number](#plylangpreludenumber)
18
19
  - [@plylang/prelude/Ord](#plylangpreludeord)
19
20
  - [@plylang/prelude/Plus](#plylangpreludeplus)
20
21
  - [@plylang/prelude/Prelude](#plylangpreludeprelude)
22
+ - [@plylang/prelude/Remainder](#plylangpreluderemainder)
21
23
  - [@plylang/prelude/Semigroup](#plylangpreludesemigroup)
22
24
  - [@plylang/prelude/Setoid](#plylangpreludesetoid)
23
25
  - [@plylang/prelude/Show](#plylangpreludeshow)
@@ -173,109 +175,6 @@ Keep the lower container's value. The upper container still runs.
173
175
 
174
176
  Keep the upper container's value. The lower container still runs.
175
177
 
176
- ## @plylang/prelude/Arithmetic
177
-
178
- ### Classes
179
-
180
- #### Arithmetic
181
-
182
- ```ply
183
- & Arithmetic a
184
- ```
185
-
186
- Arithmetic methods share one instance.
187
-
188
- #### add
189
-
190
- ```ply
191
- add ( Arithmetic a => a a -- a )
192
- ```
193
-
194
- The lower value plus the upper one.
195
-
196
- #### sub
197
-
198
- ```ply
199
- sub ( Arithmetic a => a a -- a )
200
- ```
201
-
202
- The upper value subtracted from the lower one.
203
-
204
- #### mult
205
-
206
- ```ply
207
- mult ( Arithmetic a => a a -- a )
208
- ```
209
-
210
- The lower value times the upper one.
211
-
212
- #### div
213
-
214
- ```ply
215
- div ( Arithmetic a => a a -- a )
216
- ```
217
-
218
- The lower value divided by the upper one. A zero divisor throws.
219
-
220
- #### mod
221
-
222
- ```ply
223
- mod ( Arithmetic a => a a -- a )
224
- ```
225
-
226
- The remainder. A zero divisor throws.
227
-
228
- #### negate
229
-
230
- ```ply
231
- negate ( Arithmetic a => a -- a )
232
- ```
233
-
234
- The sign flipped.
235
-
236
- #### zero
237
-
238
- ```ply
239
- zero ( Arithmetic a => -- a )
240
- ```
241
-
242
- The value add leaves unchanged.
243
-
244
- #### one
245
-
246
- ```ply
247
- one ( Arithmetic a => -- a )
248
- ```
249
-
250
- The value multiply leaves unchanged.
251
-
252
- ### Instances
253
-
254
- - Arithmetic Int
255
- - Arithmetic Num
256
-
257
- ### Words
258
-
259
- #### inc
260
-
261
- ```ply
262
- : inc ( Arithmetic a => a -- a )
263
- ```
264
-
265
- #### dec
266
-
267
- ```ply
268
- : dec ( Arithmetic a => a -- a )
269
- ```
270
-
271
- #### abs
272
-
273
- ```ply
274
- : abs ( Arithmetic a => Ord a => a -- a )
275
- ```
276
-
277
- The value with a negative sign flipped. NaN stays NaN, and -0 stays -0.
278
-
279
178
  ## @plylang/prelude/Bifunctor
280
179
 
281
180
  ### Classes
@@ -533,6 +432,58 @@ An equal result keeps the earlier element.
533
432
 
534
433
  The elements ordered by lte. An equal element keeps the earlier place.
535
434
 
435
+ ## @plylang/prelude/Fractional
436
+
437
+ ### Classes
438
+
439
+ #### Fractional
440
+
441
+ ```ply
442
+ & Number a => Fractional a
443
+ ```
444
+
445
+ #### fdiv
446
+
447
+ ```ply
448
+ fdiv ( Fractional a => a a -- a )
449
+ ```
450
+
451
+ #### floor
452
+
453
+ ```ply
454
+ floor ( Fractional a => a -- a )
455
+ ```
456
+
457
+ #### ceil
458
+
459
+ ```ply
460
+ ceil ( Fractional a => a -- a )
461
+ ```
462
+
463
+ #### round
464
+
465
+ ```ply
466
+ round ( Fractional a => a -- a )
467
+ ```
468
+
469
+ #### trunc
470
+
471
+ ```ply
472
+ trunc ( Fractional a => a -- a )
473
+ ```
474
+
475
+ ### Instances
476
+
477
+ - Fractional Num
478
+
479
+ ### Words
480
+
481
+ #### recip
482
+
483
+ ```ply
484
+ : recip ( Fractional a => a -- a )
485
+ ```
486
+
536
487
  ## @plylang/prelude/Functor
537
488
 
538
489
  ### Classes
@@ -691,6 +642,83 @@ The value concat leaves unchanged.
691
642
  - Monoid (Array a)
692
643
  - Monoid Ordering
693
644
 
645
+ ## @plylang/prelude/Number
646
+
647
+ ### Classes
648
+
649
+ #### Number
650
+
651
+ ```ply
652
+ & Number a
653
+ ```
654
+
655
+ #### add
656
+
657
+ ```ply
658
+ add ( Number a => a a -- a )
659
+ ```
660
+
661
+ #### sub
662
+
663
+ ```ply
664
+ sub ( Number a => a a -- a )
665
+ ```
666
+
667
+ #### mul
668
+
669
+ ```ply
670
+ mul ( Number a => a a -- a )
671
+ ```
672
+
673
+ #### zero
674
+
675
+ ```ply
676
+ zero ( Number a => -- a )
677
+ ```
678
+
679
+ #### one
680
+
681
+ ```ply
682
+ one ( Number a => -- a )
683
+ ```
684
+
685
+ ### Instances
686
+
687
+ - Number Int
688
+ - Number Num
689
+
690
+ ### Words
691
+
692
+ #### inc
693
+
694
+ ```ply
695
+ : inc ( Number a => a -- a )
696
+ ```
697
+
698
+ #### dec
699
+
700
+ ```ply
701
+ : dec ( Number a => a -- a )
702
+ ```
703
+
704
+ #### negate
705
+
706
+ ```ply
707
+ : negate ( Number a => a -- a )
708
+ ```
709
+
710
+ #### sign
711
+
712
+ ```ply
713
+ : sign ( Number a => Ord a => a -- a )
714
+ ```
715
+
716
+ #### abs
717
+
718
+ ```ply
719
+ : abs ( Number a => Ord a => a -- a )
720
+ ```
721
+
694
722
  ## @plylang/prelude/Ord
695
723
 
696
724
  ### Classes
@@ -879,78 +907,6 @@ ap ( Apply f => (f a) (f (a -- b)) -- (f b) )
879
907
 
880
908
  Each value run with the quotation beside it. The quotations are on top.
881
909
 
882
- #### Arithmetic
883
-
884
- ```ply
885
- & Arithmetic a
886
- ```
887
-
888
- Arithmetic methods share one instance.
889
-
890
- #### add
891
-
892
- ```ply
893
- add ( Arithmetic a => a a -- a )
894
- ```
895
-
896
- The lower value plus the upper one.
897
-
898
- #### sub
899
-
900
- ```ply
901
- sub ( Arithmetic a => a a -- a )
902
- ```
903
-
904
- The upper value subtracted from the lower one.
905
-
906
- #### mult
907
-
908
- ```ply
909
- mult ( Arithmetic a => a a -- a )
910
- ```
911
-
912
- The lower value times the upper one.
913
-
914
- #### div
915
-
916
- ```ply
917
- div ( Arithmetic a => a a -- a )
918
- ```
919
-
920
- The lower value divided by the upper one. A zero divisor throws.
921
-
922
- #### mod
923
-
924
- ```ply
925
- mod ( Arithmetic a => a a -- a )
926
- ```
927
-
928
- The remainder. A zero divisor throws.
929
-
930
- #### negate
931
-
932
- ```ply
933
- negate ( Arithmetic a => a -- a )
934
- ```
935
-
936
- The sign flipped.
937
-
938
- #### zero
939
-
940
- ```ply
941
- zero ( Arithmetic a => -- a )
942
- ```
943
-
944
- The value add leaves unchanged.
945
-
946
- #### one
947
-
948
- ```ply
949
- one ( Arithmetic a => -- a )
950
- ```
951
-
952
- The value multiply leaves unchanged.
953
-
954
910
  #### Bifunctor
955
911
 
956
912
  ```ply
@@ -1028,6 +984,42 @@ fold ( Foldable f => (f a) b (b a -- b) -- b )
1028
984
 
1029
985
  Walk from the left. The initial value sits under the quotation.
1030
986
 
987
+ #### Fractional
988
+
989
+ ```ply
990
+ & Number a => Fractional a
991
+ ```
992
+
993
+ #### fdiv
994
+
995
+ ```ply
996
+ fdiv ( Fractional a => a a -- a )
997
+ ```
998
+
999
+ #### floor
1000
+
1001
+ ```ply
1002
+ floor ( Fractional a => a -- a )
1003
+ ```
1004
+
1005
+ #### ceil
1006
+
1007
+ ```ply
1008
+ ceil ( Fractional a => a -- a )
1009
+ ```
1010
+
1011
+ #### round
1012
+
1013
+ ```ply
1014
+ round ( Fractional a => a -- a )
1015
+ ```
1016
+
1017
+ #### trunc
1018
+
1019
+ ```ply
1020
+ trunc ( Fractional a => a -- a )
1021
+ ```
1022
+
1031
1023
  #### Functor
1032
1024
 
1033
1025
  ```ply
@@ -1133,6 +1125,42 @@ empty ( Monoid a => -- a )
1133
1125
 
1134
1126
  The value concat leaves unchanged.
1135
1127
 
1128
+ #### Number
1129
+
1130
+ ```ply
1131
+ & Number a
1132
+ ```
1133
+
1134
+ #### add
1135
+
1136
+ ```ply
1137
+ add ( Number a => a a -- a )
1138
+ ```
1139
+
1140
+ #### sub
1141
+
1142
+ ```ply
1143
+ sub ( Number a => a a -- a )
1144
+ ```
1145
+
1146
+ #### mul
1147
+
1148
+ ```ply
1149
+ mul ( Number a => a a -- a )
1150
+ ```
1151
+
1152
+ #### zero
1153
+
1154
+ ```ply
1155
+ zero ( Number a => -- a )
1156
+ ```
1157
+
1158
+ #### one
1159
+
1160
+ ```ply
1161
+ one ( Number a => -- a )
1162
+ ```
1163
+
1136
1164
  #### Ord
1137
1165
 
1138
1166
  ```ply
@@ -1165,6 +1193,24 @@ init ( Plus f => -- (f a) )
1165
1193
 
1166
1194
  The value that loses. alt with it changes nothing.
1167
1195
 
1196
+ #### Remainder
1197
+
1198
+ ```ply
1199
+ & Number a => Remainder a
1200
+ ```
1201
+
1202
+ #### quotRem
1203
+
1204
+ ```ply
1205
+ quotRem ( Remainder a => a a -- a a )
1206
+ ```
1207
+
1208
+ #### divMod
1209
+
1210
+ ```ply
1211
+ divMod ( Remainder a => a a -- a a )
1212
+ ```
1213
+
1168
1214
  #### Semigroup
1169
1215
 
1170
1216
  ```ply
@@ -1290,26 +1336,6 @@ Keep the lower container's value. The upper container still runs.
1290
1336
 
1291
1337
  Keep the upper container's value. The lower container still runs.
1292
1338
 
1293
- #### inc
1294
-
1295
- ```ply
1296
- : inc ( Arithmetic a => a -- a )
1297
- ```
1298
-
1299
- #### dec
1300
-
1301
- ```ply
1302
- : dec ( Arithmetic a => a -- a )
1303
- ```
1304
-
1305
- #### abs
1306
-
1307
- ```ply
1308
- : abs ( Arithmetic a => Ord a => a -- a )
1309
- ```
1310
-
1311
- The value with a negative sign flipped. NaN stays NaN, and -0 stays -0.
1312
-
1313
1339
  #### mapLeft
1314
1340
 
1315
1341
  ```ply
@@ -1450,6 +1476,12 @@ An equal result keeps the earlier element.
1450
1476
 
1451
1477
  The elements ordered by lte. An equal element keeps the earlier place.
1452
1478
 
1479
+ #### recip
1480
+
1481
+ ```ply
1482
+ : recip ( Fractional a => a -- a )
1483
+ ```
1484
+
1453
1485
  #### flip
1454
1486
 
1455
1487
  ```ply
@@ -1464,6 +1496,36 @@ The elements ordered by lte. An equal element keeps the earlier place.
1464
1496
 
1465
1497
  The lower value implies the upper one.
1466
1498
 
1499
+ #### sign
1500
+
1501
+ ```ply
1502
+ : sign ( Number a => Ord a => a -- a )
1503
+ ```
1504
+
1505
+ #### negate
1506
+
1507
+ ```ply
1508
+ : negate ( Number a => a -- a )
1509
+ ```
1510
+
1511
+ #### abs
1512
+
1513
+ ```ply
1514
+ : abs ( Number a => Ord a => a -- a )
1515
+ ```
1516
+
1517
+ #### inc
1518
+
1519
+ ```ply
1520
+ : inc ( Number a => a -- a )
1521
+ ```
1522
+
1523
+ #### dec
1524
+
1525
+ ```ply
1526
+ : dec ( Number a => a -- a )
1527
+ ```
1528
+
1467
1529
  #### lt
1468
1530
 
1469
1531
  ```ply
@@ -1527,6 +1589,30 @@ Lower bound, upper bound, then the value. A value outside the bounds becomes the
1527
1589
  Folds with alt, starting from init.
1528
1590
  Maybe keeps the first Just. Array appends every piece, lower first.
1529
1591
 
1592
+ #### quot
1593
+
1594
+ ```ply
1595
+ : quot ( Remainder a => a a -- a )
1596
+ ```
1597
+
1598
+ #### rem
1599
+
1600
+ ```ply
1601
+ : rem ( Remainder a => a a -- a )
1602
+ ```
1603
+
1604
+ #### div
1605
+
1606
+ ```ply
1607
+ : div ( Remainder a => a a -- a )
1608
+ ```
1609
+
1610
+ #### mod
1611
+
1612
+ ```ply
1613
+ : mod ( Remainder a => a a -- a )
1614
+ ```
1615
+
1530
1616
  #### sequence
1531
1617
 
1532
1618
  ```ply
@@ -1535,6 +1621,59 @@ Maybe keeps the first Just. Array appends every piece, lower first.
1535
1621
 
1536
1622
  The applicative of the traversable. The inner values stay in order.
1537
1623
 
1624
+ ## @plylang/prelude/Remainder
1625
+
1626
+ ### Classes
1627
+
1628
+ #### Remainder
1629
+
1630
+ ```ply
1631
+ & Number a => Remainder a
1632
+ ```
1633
+
1634
+ #### quotRem
1635
+
1636
+ ```ply
1637
+ quotRem ( Remainder a => a a -- a a )
1638
+ ```
1639
+
1640
+ #### divMod
1641
+
1642
+ ```ply
1643
+ divMod ( Remainder a => a a -- a a )
1644
+ ```
1645
+
1646
+ ### Instances
1647
+
1648
+ - Remainder Int
1649
+ - Remainder Num
1650
+
1651
+ ### Words
1652
+
1653
+ #### quot
1654
+
1655
+ ```ply
1656
+ : quot ( Remainder a => a a -- a )
1657
+ ```
1658
+
1659
+ #### rem
1660
+
1661
+ ```ply
1662
+ : rem ( Remainder a => a a -- a )
1663
+ ```
1664
+
1665
+ #### div
1666
+
1667
+ ```ply
1668
+ : div ( Remainder a => a a -- a )
1669
+ ```
1670
+
1671
+ #### mod
1672
+
1673
+ ```ply
1674
+ : mod ( Remainder a => a a -- a )
1675
+ ```
1676
+
1538
1677
  ## @plylang/prelude/Semigroup
1539
1678
 
1540
1679
  ### Classes
package/dist/Chain.d.ply CHANGED
@@ -6,7 +6,7 @@ language 1
6
6
 
7
7
  ~ "Applicative" append
8
8
 
9
- ~ "Arithmetic" mult
9
+ ~ "Number" mul
10
10
 
11
11
  .. Apply a quotation that returns a container, and join the results. The quotation is on top.
12
12
  & Apply f => Chain f
@@ -10,7 +10,7 @@ language 1
10
10
 
11
11
  ~ "Ord" Ord, lt, lte
12
12
 
13
- ~ "Arithmetic" add, sub, inc
13
+ ~ "Number" add, sub, inc
14
14
 
15
15
  ~ "Logical" and, or, not
16
16
 
package/dist/Foldable.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { append, prepend, of_array } from "./Applicative.js";
2
- import { inc, add_num, div_num, mod_num, mult_num, negate_num, one_num, sub_num, zero_num } from "./Arithmetic.js";
2
+ import { inc, add_num, mul_num, one_num, sub_num, zero_num } from "./Number.js";
3
3
  import { and_bool, not_bool, or_bool } from "./Logical.js";
4
4
  import { ap_array } from "./Apply.js";
5
5
  import { concat_array } from "./Semigroup.js";
@@ -12,7 +12,7 @@ export const Store = (v0, v1) => ({ $$tag: "Store", empty: v0, value: v1 });
12
12
 
13
13
  export const Keyed = (v0, v1, v2) => ({ $$tag: "Keyed", idx: v0, item: v1, key: v2 });
14
14
 
15
- const v6 = ({ add: add_num, sub: sub_num, mult: mult_num, div: div_num, mod: mod_num, negate: negate_num, zero: zero_num, one: one_num });
15
+ const v6 = ({ add: add_num, sub: sub_num, mul: mul_num, zero: zero_num, one: one_num });
16
16
  const v274 = ({ fold: fold_array });
17
17
  const v279 = ({ map: map_array });
18
18
  const v280 = ({ ap: ap_array, Functor: v279 });
@@ -0,0 +1,31 @@
1
+ language 1
2
+
3
+ @ Fractional, fdiv, floor, ceil, round, trunc, recip
4
+
5
+ ~ "Number" Number, one
6
+
7
+ & Number a => Fractional a
8
+ fdiv ( a a -- a )
9
+ floor ( a -- a )
10
+ ceil ( a -- a )
11
+ round ( a -- a )
12
+ trunc ( a -- a )
13
+
14
+ : recip ( Fractional a => a -- a )
15
+
16
+ # Fractional Num
17
+ fdiv = fdiv_num
18
+ floor = floor_num
19
+ ceil = ceil_num
20
+ round = round_num
21
+ trunc = trunc_num
22
+
23
+ : foreign fdiv_num ( Num Num -- Num )
24
+
25
+ : foreign floor_num ( Num -- Num )
26
+
27
+ : foreign ceil_num ( Num -- Num )
28
+
29
+ : foreign round_num ( Num -- Num )
30
+
31
+ : foreign trunc_num ( Num -- Num )
@@ -0,0 +1,11 @@
1
+ import { fdiv_num, floor_num, ceil_num, round_num, trunc_num } from "../foreign/Fractional.js";
2
+ export { fdiv_num, floor_num, ceil_num, round_num, trunc_num };
3
+
4
+ export function recip(v5, v6) {
5
+ const v7 = v5.Number;
6
+ const v8 = v7.one;
7
+ const v9 = v8();
8
+ const v10 = v5.fdiv;
9
+ const v11 = v10(v9, v6);
10
+ return v11;
11
+ }
@@ -2,7 +2,7 @@ language 1
2
2
 
3
3
  @ Functor, map, flip
4
4
 
5
- ~ "Arithmetic" mult, add
5
+ ~ "Number" mul, add
6
6
 
7
7
  .. Apply a quotation inside the container. The quotation is on top.
8
8
  & Functor f
@@ -0,0 +1,56 @@
1
+ language 1
2
+
3
+ @ Number, add, sub, mul, sign, zero, one, negate, abs, inc, dec
4
+
5
+ ~ "Ord" Ord, lt, gt
6
+
7
+ & Number a
8
+ add ( a a -- a )
9
+ sub ( a a -- a )
10
+ mul ( a a -- a )
11
+ zero ( -- a )
12
+ one ( -- a )
13
+
14
+ : inc ( Number a => a -- a )
15
+
16
+ : dec ( Number a => a -- a )
17
+
18
+ : negate ( Number a => a -- a )
19
+
20
+ : sign ( Number a => Ord a => a -- a )
21
+
22
+ : abs ( Number a => Ord a => a -- a )
23
+
24
+ # Number Int
25
+ add = add_int
26
+ sub = sub_int
27
+ mul = mul_int
28
+ zero = zero_int
29
+ one = one_int
30
+
31
+ : foreign add_int ( Int Int -- Int )
32
+
33
+ : foreign sub_int ( Int Int -- Int )
34
+
35
+ : foreign mul_int ( Int Int -- Int )
36
+
37
+ : zero_int ( -- Int )
38
+
39
+ : one_int ( -- Int )
40
+
41
+ # Number Num
42
+ add = add_num
43
+ sub = sub_num
44
+ mul = mul_num
45
+ zero = zero_num
46
+ one = one_num
47
+
48
+ : foreign add_num ( Num Num -- Num )
49
+
50
+ : foreign sub_num ( Num Num -- Num )
51
+
52
+ : foreign mul_num ( Num Num -- Num )
53
+
54
+ : zero_num ( -- Num )
55
+
56
+ : one_num ( -- Num )
package/dist/Number.js ADDED
@@ -0,0 +1,90 @@
1
+ import { lt, gt } from "./Ord.js";
2
+ import { add_int, sub_int, mul_int, add_num, sub_num, mul_num } from "../foreign/Number.js";
3
+ export { add_int, sub_int, mul_int, add_num, sub_num, mul_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 negate(v27, v28) {
22
+ const v29 = v27.zero;
23
+ const v30 = v29();
24
+ const v31 = v27.sub;
25
+ const v32 = v31(v30, v28);
26
+ return v32;
27
+ }
28
+
29
+ export function sign(v68, v69, v70) {
30
+ const v71 = v68.zero;
31
+ const v72 = v71();
32
+ const v73 = gt(v69, v70, v72);
33
+ let v119;
34
+ if (v73) {
35
+ const v108 = v68.one;
36
+ const v109 = v108();
37
+ v119 = v109;
38
+ } else {
39
+ const v110 = v68.zero;
40
+ const v111 = v110();
41
+ const v112 = lt(v69, v70, v111);
42
+ let v113;
43
+ if (v112) {
44
+ const v114 = v68.one;
45
+ const v115 = v114();
46
+ const v116 = negate(v68, v115);
47
+ v113 = v116;
48
+ } else {
49
+ const v117 = v68.zero;
50
+ const v118 = v117();
51
+ v113 = v118;
52
+ }
53
+ v119 = v113;
54
+ }
55
+ return v119;
56
+ }
57
+
58
+ export function abs(v131, v132, v133) {
59
+ const v134 = v131.zero;
60
+ const v135 = v134();
61
+ const v136 = lt(v132, v133, v135);
62
+ let v142;
63
+ if (v136) {
64
+ const v141 = negate(v131, v133);
65
+ v142 = v141;
66
+ } else {
67
+ v142 = v133;
68
+ }
69
+ return v142;
70
+ }
71
+
72
+ export function zero_int() {
73
+ const v143 = 0n;
74
+ return v143;
75
+ }
76
+
77
+ export function one_int() {
78
+ const v144 = 1n;
79
+ return v144;
80
+ }
81
+
82
+ export function zero_num() {
83
+ const v145 = 0;
84
+ return v145;
85
+ }
86
+
87
+ export function one_num() {
88
+ const v146 = 1;
89
+ return v146;
90
+ }
@@ -1,6 +1,6 @@
1
1
  language 1
2
2
 
3
- @ Alt, alt, Alternative, guard, Applicative, of, append, prepend, Apply, ap, lift2, lift3, apFirst, apSecond, Arithmetic, add, sub, mult, div, mod, negate, zero, one, inc, dec, abs, Bifunctor, bimap, mapLeft, mapRight, Chain, chain, join, compose, id, curry2, curry3, Filterable, filter, partition, reject, Foldable, fold, size, all, any, none, elem, intercalate, foldMap, reverse, sortBy, sort, Functor, map, flip, Group, invert, Logical, and, or, not, truth, falsity, implies, Monad, Monoid, empty, Ord, lte, lt, gt, gte, min, max, clamp, compare, Plus, init, oneOf, Semigroup, concat, Setoid, equal, Show, show, Traversable, traverse, sequence, Ordering, LT, EQ, GT
3
+ @ Alt, alt, Alternative, guard, Applicative, of, append, prepend, Apply, ap, lift2, lift3, apFirst, apSecond, Bifunctor, bimap, mapLeft, mapRight, Chain, chain, join, compose, id, curry2, curry3, Filterable, filter, partition, reject, Foldable, fold, size, all, any, none, elem, intercalate, foldMap, reverse, sortBy, sort, Fractional, fdiv, floor, ceil, round, trunc, recip, Functor, map, flip, Group, invert, Logical, and, or, not, truth, falsity, implies, Monad, Monoid, empty, Number, add, sub, mul, sign, zero, one, negate, abs, inc, dec, Ord, lte, lt, gt, gte, min, max, clamp, compare, Plus, init, oneOf, Remainder, quotRem, quot, rem, divMod, div, mod, Semigroup, concat, Setoid, equal, Show, show, Traversable, traverse, sequence, Ordering, LT, EQ, GT
4
4
 
5
5
  ~ "Alt" Alt, alt
6
6
 
@@ -10,8 +10,6 @@ language 1
10
10
 
11
11
  ~ "Apply" Apply, ap, lift2, lift3, apFirst, apSecond
12
12
 
13
- ~ "Arithmetic" Arithmetic, add, sub, mult, div, mod, negate, zero, one, inc, dec, abs
14
-
15
13
  ~ "Bifunctor" Bifunctor, bimap, mapLeft, mapRight
16
14
 
17
15
  ~ "Chain" Chain, chain, join
@@ -22,6 +20,8 @@ language 1
22
20
 
23
21
  ~ "Foldable" Foldable, fold, size, all, any, none, elem, intercalate, foldMap, reverse, sortBy, sort
24
22
 
23
+ ~ "Fractional" Fractional, fdiv, floor, ceil, round, trunc, recip
24
+
25
25
  ~ "Functor" Functor, map, flip
26
26
 
27
27
  ~ "Group" Group, invert
@@ -32,10 +32,14 @@ language 1
32
32
 
33
33
  ~ "Monoid" Monoid, empty
34
34
 
35
+ ~ "Number" Number, add, sub, mul, sign, zero, one, negate, abs, inc, dec
36
+
35
37
  ~ "Ord" Ord, lte, lt, gt, gte, min, max, clamp, compare
36
38
 
37
39
  ~ "Plus" Plus, init, oneOf
38
40
 
41
+ ~ "Remainder" Remainder, quotRem, quot, rem, divMod, div, mod
42
+
39
43
  ~ "Semigroup" Semigroup, concat
40
44
 
41
45
  ~ "Setoid" Setoid, equal
package/dist/Prelude.js CHANGED
@@ -1,15 +1,17 @@
1
1
  export { guard } from "./Alternative.js";
2
2
  export { append, prepend } from "./Applicative.js";
3
3
  export { lift2, lift3, apFirst, apSecond } from "./Apply.js";
4
- export { inc, dec, abs } from "./Arithmetic.js";
5
4
  export { mapLeft, mapRight } from "./Bifunctor.js";
6
5
  export { join } from "./Chain.js";
7
6
  export { compose, id, curry2, curry3 } from "./Composition.js";
8
7
  export { reject } from "./Filterable.js";
9
8
  export { size, all, any, none, elem, intercalate, foldMap, reverse, sortBy, sort } from "./Foldable.js";
9
+ export { recip } from "./Fractional.js";
10
10
  export { flip } from "./Functor.js";
11
11
  export { implies } from "./Logical.js";
12
+ export { sign, negate, abs, inc, dec } from "./Number.js";
12
13
  export { lt, gt, gte, min, max, clamp, compare } from "./Ord.js";
13
14
  export { oneOf } from "./Plus.js";
15
+ export { quot, rem, div, mod } from "./Remainder.js";
14
16
  export { sequence } from "./Traversable.js";
15
17
  export { LT, EQ, GT } from "./Types.js";
@@ -0,0 +1,33 @@
1
+ language 1
2
+
3
+ @ Remainder, quotRem, quot, rem, divMod, div, mod
4
+
5
+ ~ "Number" Number
6
+
7
+ & Number a => Remainder a
8
+ quotRem ( a a -- a a )
9
+ divMod ( a a -- a a )
10
+
11
+ : quot ( Remainder a => a a -- a )
12
+
13
+ : rem ( Remainder a => a a -- a )
14
+
15
+ : div ( Remainder a => a a -- a )
16
+
17
+ : mod ( Remainder a => a a -- a )
18
+
19
+ # Remainder Int
20
+ quotRem = quotRem_int
21
+ divMod = divMod_int
22
+
23
+ : foreign quotRem_int ( Int Int -- Int Int )
24
+
25
+ : foreign divMod_int ( Int Int -- Int Int )
26
+
27
+ # Remainder Num
28
+ quotRem = quotRem_num
29
+ divMod = divMod_num
30
+
31
+ : foreign quotRem_num ( Num Num -- Num Num )
32
+
33
+ : foreign divMod_num ( Num Num -- Num Num )
@@ -0,0 +1,26 @@
1
+ import { quotRem_int, divMod_int, quotRem_num, divMod_num } from "../foreign/Remainder.js";
2
+ export { quotRem_int, divMod_int, quotRem_num, divMod_num };
3
+
4
+ export function quot(v0, v1, v2) {
5
+ const v3 = v0.quotRem;
6
+ const [v4, v5] = v3(v1, v2);
7
+ return v4;
8
+ }
9
+
10
+ export function rem(v6, v7, v8) {
11
+ const v9 = v6.quotRem;
12
+ const [v10, v11] = v9(v7, v8);
13
+ return v11;
14
+ }
15
+
16
+ export function div(v12, v13, v14) {
17
+ const v15 = v12.divMod;
18
+ const [v16, v17] = v15(v13, v14);
19
+ return v16;
20
+ }
21
+
22
+ export function mod(v18, v19, v20) {
23
+ const v21 = v18.divMod;
24
+ const [v22, v23] = v21(v19, v20);
25
+ return v23;
26
+ }
@@ -14,7 +14,9 @@ language 1
14
14
 
15
15
  ~ "Semigroup" concat
16
16
 
17
- ~ "Arithmetic" add, sub, div, mod, mult, inc, dec
17
+ ~ "Number" add, sub, mul, inc, dec
18
+
19
+ ~ "Remainder" div, mod
18
20
 
19
21
  .. Visit each value with a quotation that returns an applicative result, and collect those results in order.
20
22
  .. Applicative already brings ap and map.
@@ -1,13 +1,15 @@
1
1
  import { size, fold_array } from "./Foldable.js";
2
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";
3
+ import { inc, dec, add_num, mul_num, one_num, sub_num, zero_num } from "./Number.js";
4
+ import { div, mod, divMod_num, quotRem_num } from "./Remainder.js";
4
5
  import { concat_array } from "./Semigroup.js";
5
6
  import { equal_num } from "./Setoid.js";
6
7
  import { of_array } from "./Applicative.js";
7
8
  import { index_array } from "../foreign/Traversable.js";
8
9
 
9
10
  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
+ const v13 = ({ add: add_num, sub: sub_num, mul: mul_num, zero: zero_num, one: one_num });
12
+ const v14 = ({ quotRem: quotRem_num, divMod: divMod_num, Number: v13 });
11
13
 
12
14
  export function sequence(v0, v1, v2) {
13
15
  const v4 = (v3) => v3;
@@ -19,40 +21,40 @@ export function sequence(v0, v1, v2) {
19
21
  export function traverseArray(v7, v8, v9) {
20
22
  const v11 = size(v10, v8);
21
23
  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;
24
+ const v15 = mod(v14, v11, v12);
25
+ const v16 = 0;
26
+ const v17 = equal_num(v15, v16);
27
+ let v33;
28
+ if (v17) {
29
+ const v30 = 0;
30
+ const v31 = go(v7, v8, v9, v30, v11);
31
+ v33 = v31;
30
32
  } else {
31
- const v30 = evenTraverse(v7, v8, v9, v11);
32
- v31 = v30;
33
+ const v32 = evenTraverse(v7, v8, v9, v11);
34
+ v33 = v32;
33
35
  }
34
- return v31;
36
+ return v33;
35
37
  }
36
38
 
37
- function pair(v32, v33) {
38
- let v35;
39
- const v34 = [v32, v33];
40
- v35 = v34;
41
- return v35;
39
+ function pair(v34, v35) {
40
+ let v37;
41
+ const v36 = [v34, v35];
42
+ v37 = v36;
43
+ return v37;
42
44
  }
43
45
 
44
- function evenTraverse(v91, v92, v93, v94) {
45
- const v96 = dec(v95, v94);
46
+ function evenTraverse(v92, v93, v94, v95) {
47
+ const v96 = dec(v13, v95);
46
48
  const v97 = 1;
47
- const v100 = go(v91, v92, v93, v97, v96);
49
+ const v100 = go(v92, v93, v94, v97, v96);
48
50
  const v129 = 0;
49
- const v130 = index_array(v92, v129);
50
- const v131 = v93(v130);
51
+ const v130 = index_array(v93, v129);
52
+ const v131 = v94(v130);
51
53
  const v132 = (v133) => {
52
54
  const v134 = of_array(v133);
53
55
  return v134;
54
56
  };
55
- const v135 = v91.Apply;
57
+ const v135 = v92.Apply;
56
58
  const v136 = v135.Functor;
57
59
  const v137 = v136.map;
58
60
  const v138 = v137(v131, v132);
@@ -60,7 +62,7 @@ function evenTraverse(v91, v92, v93, v94) {
60
62
  const v142 = concat_array(v139, v140);
61
63
  return v142;
62
64
  };
63
- const v144 = v91.Apply;
65
+ const v144 = v92.Apply;
64
66
  const v145 = lift2(v144, v138, v100, v143);
65
67
  return v145;
66
68
  }
@@ -84,7 +86,7 @@ function go(v156, v157, v158, v159, v160) {
84
86
 
85
87
  function go2(v167, v168, v169, v170) {
86
88
  const v176 = index_array(v168, v170);
87
- const v177 = inc(v95, v170);
89
+ const v177 = inc(v13, v170);
88
90
  const v178 = index_array(v168, v177);
89
91
  const v179 = v169(v176);
90
92
  const v180 = v169(v178);
@@ -99,9 +101,9 @@ function go2(v167, v168, v169, v170) {
99
101
 
100
102
  function goDefault(v224, v225, v226, v227, v228) {
101
103
  const v229 = 4;
102
- const v230 = div_num(v228, v229);
104
+ const v230 = div(v14, v228, v229);
103
105
  const v231 = 2;
104
- const v232 = mult_num(v230, v231);
106
+ const v232 = mul_num(v230, v231);
105
107
  const v240 = leftGo(v224, v227, v232);
106
108
  const v245 = rigthGo(v224, v228, v227, v232);
107
109
  const v251 = v240(v225, v226);
@@ -0,0 +1,23 @@
1
+ export function fdiv_num(a, b) {
2
+ const quotient = a / b
3
+ if (b === 0 || !Number.isFinite(quotient)) {
4
+ throw new Error('division by zero')
5
+ }
6
+ return quotient
7
+ }
8
+
9
+ export function floor_num(a) {
10
+ return Math.floor(a)
11
+ }
12
+
13
+ export function ceil_num(a) {
14
+ return Math.ceil(a)
15
+ }
16
+
17
+ export function round_num(a) {
18
+ return Math.round(a)
19
+ }
20
+
21
+ export function trunc_num(a) {
22
+ return Math.trunc(a)
23
+ }
@@ -0,0 +1,23 @@
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 mul_int(a, b) {
10
+ return a * b
11
+ }
12
+
13
+ export function add_num(a, b) {
14
+ return a + b
15
+ }
16
+
17
+ export function sub_num(a, b) {
18
+ return a - b
19
+ }
20
+
21
+ export function mul_num(a, b) {
22
+ return a * b
23
+ }
@@ -0,0 +1,32 @@
1
+ const zeroError = () => {
2
+ throw new RangeError('Division by zero')
3
+ }
4
+
5
+ export function quotRem_int(a, b) {
6
+ if (b === 0n) zeroError()
7
+ return [a / b, a % b]
8
+ }
9
+
10
+ export function divMod_int(a, b) {
11
+ if (b === 0n) zeroError()
12
+ const q = a / b
13
+ const r = a % b
14
+ if (r !== 0n && r < 0n !== b < 0n) {
15
+ return [q - 1n, r + b]
16
+ }
17
+ return [q, r]
18
+ }
19
+
20
+ export function quotRem_num(a, b) {
21
+ const quotient = Math.trunc(a / b)
22
+ if (b === 0 || !Number.isFinite(quotient)) zeroError()
23
+ return [quotient, a % b]
24
+ }
25
+
26
+ export function divMod_num(a, b) {
27
+ const quotient = Math.floor(a / b)
28
+ if (b === 0 || !Number.isFinite(quotient)) zeroError()
29
+ const remainder = a % b
30
+ const modR = remainder !== 0 && remainder < 0 !== b < 0 ? remainder + b : remainder
31
+ return [quotient === 0 ? 0 : quotient, modR === 0 ? 0 : modR]
32
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plylang/prelude",
3
3
  "description": "Ply prelude",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,83 +0,0 @@
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 )
@@ -1,54 +0,0 @@
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
- }
@@ -1,57 +0,0 @@
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
- }