版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
1.4 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getAlternativeMonoid = exports.altAll = void 0;
  4. /**
  5. * The `Alternative` type class extends the `Alt` type class with a value that should be the left and right identity for `alt`.
  6. *
  7. * It is similar to `Monoid`, except that it applies to types of kind `* -> *`, like `Array` or `Option`, rather than
  8. * concrete types like `string` or `number`.
  9. *
  10. * `Alternative` instances should satisfy the following laws:
  11. *
  12. * 1. Left identity: `A.alt(zero, fa) <-> fa`
  13. * 2. Right identity: `A.alt(fa, zero) <-> fa`
  14. * 3. Annihilation: `A.map(zero, f) <-> zero`
  15. * 4. Distributivity: `A.ap(A.alt(fab, gab), fa) <-> A.alt(A.ap(fab, fa), A.ap(gab, fa))`
  16. * 5. Annihilation: `A.ap(zero, fa) <-> zero`
  17. *
  18. * @since 2.0.0
  19. */
  20. var Alt_1 = require("./Alt");
  21. var Apply_1 = require("./Apply");
  22. function altAll(F) {
  23. return (0, Alt_1.altAll)(F)(F.zero());
  24. }
  25. exports.altAll = altAll;
  26. function getAlternativeMonoid(F) {
  27. var f = (0, Apply_1.getApplySemigroup)(F);
  28. return function (S) {
  29. var SF = f(S);
  30. return {
  31. concat: function (first, second) {
  32. return F.alt(SF.concat(first, second), function () { return F.alt(first, function () { return second; }); });
  33. },
  34. empty: F.zero()
  35. };
  36. };
  37. }
  38. exports.getAlternativeMonoid = getAlternativeMonoid;