-
Notifications
You must be signed in to change notification settings - Fork 376
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
Fix for monad identity laws. #136
Conversation
@@ -34,6 +34,9 @@ Sum.prototype[equals] = function(x) { | |||
return this.v.equals ? this.v.equals(x.v) : this.v === x.v; | |||
}; | |||
|
|||
// Special function for monad identity laws. | |||
const f = x => Id.of(x + x); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the +
for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it, x => Id.of(x)
is simply the same as Id.of
. In that case, there is no difference between the leftIdentity
and rightIdentity
test cases. Any non-trivial function that returns an Id should do here, I just picked something simple :).
I found another issue in that the Monoid laws currently assume the Monoid implements an |
@jwoudenberg you're linking to the Monad laws there. |
@gabejohnson Thanks for pointing that out :). My remark stands though, see this new and improved link. |
PR would be amazing😉 On Wed, 15 Jun 2016, 19:04 Jasper Woudenberg, [email protected]
|
I'll see what I can do :). |
This is fixed in #171 |
I believe there is an issue with the implementation of the identity monad laws. Specifically, the identity function is not a valid argument to
chain
, because it will not return a value of the same Monad (a requirement inherited from Chain).The reason this has not caused an error so far is because is an implementation detail of the Monad it is tested against. I believe other valid monads can run into issues when testing them against the law in it's current state.
My proposed fix is passing in a monad-returning function
f
to test against instead of usingidentity
. I realize this is not such a nice solution in the sense that it changes the API of these tests with regards of the laws of the other tests, so a better solution would be welcome.The only trivial monad-returning function we could use is
t.of
, but using that would result in identiticalleftIdentity
andrightIdentity
tests. Another approach is to build a simplef
in the law file itself, but it would require knowledge of the type ofx
, which would compromise the generality of the test.