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

Make Compose to be a proper Applicative #141

Merged
merged 1 commit into from
Jun 15, 2016

Conversation

rpominov
Copy link
Member

@rpominov rpominov commented Jun 5, 2016

@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

};

Compose.of = function(x) {
return new Compose(F.of(G.of(x)));
};
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@rpominov rpominov Jun 5, 2016

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

@rpominov
Copy link
Member Author

@SimonRichardson, since you're merging PRs today, do you think this one's also ok to merge? 😅
@joneshf, maybe you could take a look as well?

@SimonRichardson
Copy link
Member

I'm not a fan of the word wrap, also should we spec it out, or just leave it?

@rpominov
Copy link
Member Author

I think in this case wrap is a type specific function that can create instances of type differently from of, probably no need to spec it somehow. But we can rename it (any suggestions on a better name?), or make Compose() behave as such function, but this will be more code inlined in spec...

@rpominov
Copy link
Member Author

rpominov commented Jun 15, 2016

Maybe we should inline wrap into the law like this:

u.map(x => new Compose(x)).sequence(Compose.of) is equivalent to new Compose(u.sequence(F.of).map(v => v.sequence(G.of)))

?

@rpominov
Copy link
Member Author

  • Removed/inlined wrap.
  • Also added "and any Applicatives F and G". More clarity can't hurt :)

@SimonRichardson
Copy link
Member

Let me know when you're done!

@rpominov
Copy link
Member Author

It's ready to merge!

@SimonRichardson SimonRichardson merged commit 6692bb3 into fantasyland:master Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants