Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify location of ‘empty’ method #162

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ the Semigroup specification.
empty :: Monoid m => () -> m
```

A value which has a Monoid must provide an `empty` method on itself or
its `constructor` object. The `empty` method takes no arguments:
A value which has a Monoid must provide an `empty` method. The `empty`
method takes no arguments:

m.empty()
m.constructor.empty()

1. `empty` must return a value of the same Monoid

Expand Down
5 changes: 2 additions & 3 deletions id.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ Id.prototype[fl.concat] = function(b) {
};

// Monoid (value must also be a Monoid)
Id[fl.empty] = function() {
return new Id(this.value[fl.empty] ? this.value[fl.empty]() : this.value.constructor[fl.empty]());
Id.prototype[fl.empty] = function() {
return new Id(this.value[fl.empty]());
};
Id.prototype[fl.empty] = Id[fl.empty];

// Foldable
Id.prototype[fl.reduce] = function(f, acc) {
Expand Down
7 changes: 3 additions & 4 deletions id_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ const Id = require('./id');
// Special type of sum for the type of string.
const Sum = tagged('v');
Sum[of] = (x) => Sum(x);
Sum[empty] = () => Sum('');
Sum.prototype[of] = Sum[of];
Sum.prototype[empty] = Sum[empty];
Sum.prototype[empty] = () => Sum('');
Sum.prototype[map] = function(f) {
return Sum(f(this.v));
};
Expand Down Expand Up @@ -90,8 +89,8 @@ exports.monad = {
};

exports.monoid = {
leftIdentity: test((x) => monoid.leftIdentity(Id[of](Sum[empty]()))(equality)(Sum[of](x))),
rightIdentity: test((x) => monoid.rightIdentity(Id[of](Sum[empty]()))(equality)(Sum[of](x)))
leftIdentity: test((x) => monoid.leftIdentity(Id[of](Sum.prototype[empty]()))(equality)(Sum[of](x))),
rightIdentity: test((x) => monoid.rightIdentity(Id[of](Sum.prototype[empty]()))(equality)(Sum[of](x)))
};

// Semigroup tests are broken otherwise for this.
Expand Down