-
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
Make Compose to be a proper Applicative #141
Conversation
}; | ||
|
||
Compose.of = function(x) { | ||
return new Compose(F.of(G.of(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.
Where are F
and G
defined?
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.
They are "any Applicatives", we can add "... for any Applicatives F
and G
" to the law, not sure if it necessary though.
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.
Also notice that the same types are mentioned in the law (Compose.wrap(u.sequence(F.of).map(v => v.sequence(G.of)))
) so it all connected.
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.
So Compose
is specific to (F, G)
in this case? Perhaps we should parameterize F
and G
as @scott-christopher did here.
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.
I thought about it, but specialized Compose
is simpler, and works fine for its purpose in this case (we don't need to define a usable Compose
type, but only one that helps to express the law).
With parameterized Compose
the law code snippets will become harder to read.
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.
I am a little unsettled that this would be a runtime error if someone copy/pasted it. And given that we have issues like #128, we should try to be more aware that what seems obvious to one or two of us, isn't necessarily good for the spec. How do you feel about making these variables explicit?
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 if we simply rename Compose
to ComposeFG
? It will be clear that it works only with F
and G
, and we won't have to complicate code.
I'm worried that with parameterized Compose the law text will became harder to grasp.
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.
If the implementation doesn't change, I will still have the same level of unsettledness. I will defer to someone else on the level of easiness/hardness.
@CrossEye, thoughts?
@SimonRichardson, since you're merging PRs today, do you think this one's also ok to merge? 😅 |
I'm not a fan of the word |
I think in this case |
Maybe we should inline wrap into the law like this:
? |
d0e2acc
to
08898b7
Compare
08898b7
to
ca31493
Compare
|
Let me know when you're done! |
It's ready to merge! |
@joneshf Pointed out that the Compose type as it currently implemented in the spec doesn't pass the Applicative laws. For instance
Compose.of(x => x).ap(Compose.of(1))
will blow up.I've also changed the letters that are used for variables and types to hopefully a bit more appropriate ones.
Checked that new code works fine in Ramda REPL