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

OneAnd: add PartialOrder and Order instances #4460

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

satorg
Copy link
Contributor

@satorg satorg commented Jun 13, 2023

  • Adds the missing PartialOrder and Order instances to OneAnd.
  • Re-arranges the PartialOrder, Order and already existing Eq instances according to their supposed resolution order.
  • Adds corresponding tests.

@satorg satorg self-assigned this Jun 13, 2023
@satorg satorg added this to the 2.10.0 milestone Jun 13, 2023
@@ -280,6 +289,19 @@ sealed abstract private[data] class OneAndLowPriority0_5 extends OneAndLowPriori
}

sealed abstract private[data] class OneAndLowPriority0 extends OneAndLowPriority0_5 {
implicit def catsDataPartialOrderForOneAnd[A, F[_]](implicit
Copy link
Member

Choose a reason for hiding this comment

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

You can put this together with Order because it's a supertype.
So if F[x] <: G[x] it's ok to put them on the same level.
But if you were to add Hash then it has to be on a separate level from Order because Eq is common between Hash and Order but neither is a subtype of the other.

Copy link
Contributor Author

@satorg satorg Jun 13, 2023

Choose a reason for hiding this comment

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

Thank you for the clarification 👍 Personally, I would like to gather them in one place (and I was considering to, initially).
However, I found out that looks like almost everywhere in Cats Order and PartialOrder are placed on different levels. Perhaps just due to an oversight though (many oversights, actually). So I was uncertain about it and decided to follow the convention – I thought it was made for a reason. But if there's no objections, I would put it together indeed.

Copy link
Member

Choose a reason for hiding this comment

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

Since those are package private traits we are free to reorder them 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joroKr21 , I tried to put Order and PartialOrder at one level. It works good indeed for Scala 2.13, but Scala 2.12 fails in multiple places with errors like this one:

[error] .../github/typelevel/cats/tests/shared/src/test/scala-2.12/cats/tests/NonEmptyStreamSuite.scala:44:42: ambiguous implicit values:
[error]  both method catsDataPartialOrderForOneAnd in class OneAndInstances of type [A, F[_]](implicit A: cats.PartialOrder[A], implicit FA: cats.PartialOrder[F[A]])cats.PartialOrder[cats.data.OneAnd[F,A]]
[error]  and method catsDataOrderForOneAnd in class OneAndInstances of type [A, F[_]](implicit A: cats.Order[A], implicit FA: cats.Order[F[A]])cats.Order[cats.data.OneAnd[F,A]]
[error]  match expected type cats.kernel.Eq[cats.data.NonEmptyStream[Int]]
[error]   checkAll("NonEmptyStream[Int]", EqTests[NonEmptyStream[Int]].eqv)
[error]                                          ^

At least, I know now, why those instances are organized in such a way across the Cats :)

Copy link
Member

Choose a reason for hiding this comment

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

Ahh damn, I think it's a bug when there are higher-kinded type parameters. Got it, thanks 👍

@satorg satorg force-pushed the add-oneand-orders branch from 5eca13f to 2999e7b Compare June 13, 2023 08:51
@satorg satorg requested a review from joroKr21 June 18, 2023 20:38
Copy link
Member

@joroKr21 joroKr21 left a comment

Choose a reason for hiding this comment

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

Cool 👍

@satorg satorg force-pushed the add-oneand-orders branch from 2999e7b to 9dab5a5 Compare June 24, 2023 23:38
Comment on lines +52 to +55
{
import Helpers.Eqed

checkAll("OneAnd[F, A]", EqTests[OneAnd[ListWrapper, Eqed]].eqv)
Copy link
Member

Choose a reason for hiding this comment

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

Were the Eq laws not already tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it may look superfluous (and probably it is). So if you don't like I am up to remove this check.

The motivation though was to give a try to the Eqed type that provides a "pure" Eq instance. So if somehow Eq is masked or overridden by Order or something and is not consistent with the laws, then it potentially could help to catch this. But I agree – it has a very little practical sense.

Also, I noticed that Eqed not in use in any other tests so decided to give it a try here.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, no, you misunderstood, I liked it!

I was just confirming that even though the Eq instance already existed, there were no existing law tests for it actually.

@satorg satorg force-pushed the add-oneand-orders branch from 9dab5a5 to 9623b83 Compare June 26, 2023 18:40
@satorg
Copy link
Contributor Author

satorg commented Jun 26, 2023

Thank you guys for looking into it, I appreciate your time. I would merge it if there are no objections.

@satorg satorg merged commit 7935833 into typelevel:main Jun 26, 2023
@satorg satorg deleted the add-oneand-orders branch June 26, 2023 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants