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

Proof of concept creating a cats-kernel module for Cats/Algebra. #786

Closed
wants to merge 2 commits into from

Conversation

milessabin
Copy link
Member

This is a follow on from https://github.com/non/cats/pull/762 taking into consideration the discussion there and on typelevel/algebra#142.

This new PR has essentially the same content as #762 but instead of merging the Algebra type classes in with the core module it adds them to a new kernel module on which we can impose binary compatibility constraints that are sufficient to meet the Algebra project's needs.

@@ -1,7 +1,14 @@
package cats
package std

trait BigIntInstances extends algebra.std.BigIntInstances {
trait BigIntInstances {
implicit val bigIntAlgebra: BigIntAlgebra =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is out of the scope of this PR, but just to jot it down while I'm thinking of it: is there any benefit to having this statically typed to BitIntAlgebra instead of just Order[BigInt]?

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 are you proposing as an alternative?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just proposing : Order[BigInt] instead of : BigIntAlgebra for the return type. As far as I know that's the approach we are taking pretty much everywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why not the Group[BigInt] here? We have it for Int, Long?

@ceedubs
Copy link
Contributor

ceedubs commented Jan 7, 2016

Is there a near-term plan for making laws/tests consistent between kernel and the rest of cats?

@milessabin
Copy link
Member Author

@ceedubs this is a proof of concept for discussion. I thought it would be better to keep the edit distance from Algebra as small as possible for the time being. Once it's completely clear that this is the direction we and Algebra want to go then we should deal with laws/tests/docs/simulacrum as a matter of urgency.

@ceedubs
Copy link
Contributor

ceedubs commented Jan 7, 2016

@milessabin that makes sense, and I agree with your approach. We don't want this to turn into a never-ending PR.

This looks good to me. I'd like to see what some algebra committers such as @non, @johnynek, @TomasMikula and @rklaehn think.

@ghost
Copy link

ghost commented Jan 7, 2016

we should deal with laws/tests/docs/simulacrum as a matter of urgency

I've been following all of this in Algebra/Cats and on many occasions I have desperately wanted to shout out about how catalysts can do this and that... but (thankfully) kept quiet so as not to interrupt the main discussion.

As you have all done a great job on consensus, now might be a good time to raise the point that sbt-catalysts/catalysts needs sorting in Cats/Algebra/Spire as well... on the build/testing side only.

def combine(x: Unit, y: Unit): Unit = ()
def empty: Unit = ()
def inverse(x: Unit): Unit = ()
implicit val unitOrder: Order[Unit] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the group here can be useful no? (Allows you do use some Monads that want Monoids on some values, e.g. Writer?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean plain Group rather than CommutativeGroup? Yes, agreed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry. I overlooked that you just removed the CommutativeGroup, but that's another issue to keep in mind with standard instances: many standard ones are commutative, but kernel won't have it, so something for algebra to keep in mind.

@johnynek
Copy link
Contributor

johnynek commented Jan 7, 2016

Re: typeclassic/simulacrum/machinist: can anyone confirm these have no runtime portion and are just generating code at compile time? Having a runtime portion makes the binary compat problem harder (obviously).

@erik-stripe
Copy link
Contributor

This PR has the potential to get gigantic. Would folks be OK with creating a long-lived branch for this and then we can all issues PRs against it? That way we aren't relying on @milessabin to do all the work.

What do you all think?

@johnynek
Copy link
Contributor

johnynek commented Jan 7, 2016

+1

On Thu, Jan 7, 2016 at 10:20 AM, Erik Osheim notifications@github.com
wrote:

This PR has the potential to get gigantic. Would folks be OK with creating
a long-lived branch for this and then we can all issues PRs against it?
That way we aren't relying on @milessabin https://github.com/milessabin
to do all the work.


Reply to this email directly or view it on GitHub
https://github.com/non/cats/pull/786#issuecomment-169762011.

P. Oscar Boykin, Ph.D. | http://twitter.com/posco | http://pobox.com/~boykin

@ceedubs
Copy link
Contributor

ceedubs commented Jan 7, 2016

I agree that we shouldn't shove all of the work into this PR. However, if people are confident that this is the way forward, I might propose merging and making sure we have issues for the items we want to fix before a 1.0 release. That way we don't have a branch that potentially diverges significantly from master and becomes a constant struggle to keep up to date.

@erik-stripe
Copy link
Contributor

The risk with merging now is that master will be in an unreleasable state until we straighten out the most pressing issues.

(For example, if cats-kernel does not export type class instances, then projects like algebra will have to either depend on cats-core or will have to duplicate those instances. IMO this is a flaw with the current PR.)

I think I'd prefer to do a branch which we will merge to master as soon as we feel like we hit a basic level of releasability. I'm also fine with merging now if other Cats devs aren't worried about this issue, but I just wanted to bring it up.

@erik-stripe
Copy link
Contributor

The reason the cats-kernel issue is subtle is that cats.std is currently implemented using a package object, which can't exist in two sub-projects. Therefore, the ways to resolve this would be:

  1. Put types from cats-kernel into cats.kernel (and cats.kernel.std) and then export/alias them into cats (and cats.std) in the cats-core sub-project.
  2. Put the type class instances in a non-standard place (e.g. cats.kernel.std) and only realias those, leaving other types in cats.
  3. Change how "std" is implemented so we don't need to use package objects, and can split these instances across cats-kernel and cats-core.
  4. Something else I haven't thought of.

@rklaehn
Copy link
Contributor

rklaehn commented Jan 7, 2016

On Thu, Jan 7, 2016 at 9:18 PM, Erik Osheim notifications@github.com
wrote:

The risk with merging now is that master will be in an unreleasable
state until we straighten out the most pressing issues.

(For example, if cats-kernel does not export type class instances, then
projects like algebra will have to either depend on cats-core or will
have to duplicate those instances. IMO this is a flaw with the current PR.)

I would consider duplicate typeclass instances much less of a problem
than duplicate typeclasses. E.g. if you have Eq[Int] in both algebra.std
and cats.std, it might not be very nice from a DRY POV, but as long as both
are law-abiding, it is not the end of the world.

The only thing that would be a problem would be

import cats.implicits._
import algebra.implicits._

// Eq[Int] does not work because of duplicate implicits

But if there is a way to prevent this, I would be in favour of leaving
instances out of cats-kernel to keep cats-kernel small. I think there are
quite a large number of instances that you can provide for e.g. Eq and
Order. Eq for all primitive types, Strings, Arrays, scala collections,
Order for all kinds of sequences, PartialOrder for sets, ...

And the number of Monoid or Group instances for primitives, arrays, scala
collections, ... is also very large.

Do we really want them all in cats-kernel? If not, where do we draw the
line?

Another thing we should not forget is to rename empty to something else
(neutral?) before doing the first release that uses cats-kernel (but not
necessarily before this PR is merged to master)

I think I'd prefer to do a branch which we will merge to master as soon as
we feel like we hit a basic level of releasability. I'm also fine with
merging now if other Cats devs aren't worried about this.


Reply to this email directly or view it on GitHub
https://github.com/non/cats/pull/786#issuecomment-169794007.

@erik-stripe
Copy link
Contributor

Yeah, I guess I am fine with not sharing instances, but we should be explicit that this is what is intended.

@rklaehn
Copy link
Contributor

rklaehn commented Jan 7, 2016

Not sharing instances would definitely make things easier for now. If we
decide to share instances there should at least be some clear criterion for
which instance we share and which we don't. E.g. you could make a case that
Eq[Int] belongs into cats-kernel, but I think the various ways to define
partial orders for sorted sets definitely do not belong in cats-kernel.

How would you deal with the problem of collisions when importing all
implicits of e.g. algebra and cats. Not at all / just tell people not to do
that?

On Thu, Jan 7, 2016 at 10:52 PM, Erik Osheim notifications@github.com
wrote:

Yeah, I guess I am fine with not sharing instances, but we should be
explicit that this is what is intended.


Reply to this email directly or view it on GitHub
https://github.com/non/cats/pull/786#issuecomment-169817557.

@milessabin
Copy link
Member Author

I'm fine with this being a branch we can all contribute to ... shall I just do that?

@milessabin
Copy link
Member Author

Unless I'm misunderstanding, I think that quite a few of @johnynek's comments would be equally applicable to Algebra as it currently stands and don't relate to issues that I've introduced in the process of moving things over?

If that's the case then I think that would be a very strong argument in favour of merging or making this into a branch that multiple parties can iterate on ... from my PoV this PR was just about the creation of cats-kernel, not also about refining its content.

@non
Copy link
Contributor

non commented Jan 8, 2016

@milessabin Yes, I think some of @johnynek's comments do apply to algebra currently. Let's try the branch idea (with an eye to merging to master relatively soon to avoid the situation @ceedubs mentions).

@ceedubs
Copy link
Contributor

ceedubs commented Jan 8, 2016

@Striation thanks, you cleared up to me why it isn't too great of an idea to merge to master right away. 👍 for an official repo branch for this.

@milessabin
Copy link
Member Author

OK, I've rebased against master and pushed to https://github.com/non/cats/tree/topic/kernel.

@rklaehn
Copy link
Contributor

rklaehn commented Jan 13, 2016

Since there is now a separate branch to track this, I guess this PR should be closed and discussion continued somewhere else ( #777 )?

@milessabin
Copy link
Member Author

Agreed ... we should capture the comments made here as separate issues.

I'm completely overloaded for the next couple of days, so any help with this would be appreciated.

@julienrf
Copy link
Contributor

julienrf commented May 1, 2016

I think this issue can be closed now?

@adelbertc
Copy link
Contributor

Fixed #1001

@adelbertc adelbertc closed this May 1, 2016
@stew stew removed the in progress label May 1, 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.

10 participants