-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 ambiguous Const
instances and add missing instances
#4458
Conversation
Const
instances and add missing instances
@nowarn("cat=unused") | ||
def traverse[F[_], C](f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] = | ||
F.pure(retag[C]) |
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.
Just a hint (feel free to disregard): with help of scalac-compat it can be addressed in a nicer way:
import org.typelevel.scalaccompat.annotation._
then
@nowarn("cat=unused") | |
def traverse[F[_], C](f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] = | |
F.pure(retag[C]) | |
def traverse[F[_], C](@unused f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] = | |
F.pure(retag[C]) |
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.
[error] ../typelevel/cats/core/src/main/scala/cats/data/Const.scala:26:12: object typelevel is not a member of package org
[error] import org.typelevel.scalaccompat.annotation._
[error] ^
[error] ../typelevel/cats/core/src/main/scala/cats/data/Const.scala:46:26: not found: type unused
[error] def traverse[F[_], C](@unused f: B => F[C])(implicit F: Applicative[F]): F[Const[A, C]] =
[error]
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.
Yeah, I guess it should work better once these changes (typelevel/sbt-typelevel#518) will be available in the current version of the plugin 🤷
Meanwhile you could add it to build.sbt
temporarily:
ThisBuild / libraryDependencies += "org.typelevel" %% "scalac-compat-annotation" % "0.1.0" % CompileTime
... or skip my initial comment about it entirely ...
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.
We have a lot of unused (and other) warnings in the project. I guess it would be good to tackle them together.
Cannot find those in your changes 🤔 |
Ah yes, I fixed the ambiguity of |
7161da3
to
feb708e
Compare
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.
Looks good to me, thank you!
|
||
implicit def catsDataFunctorForConst[C]: Functor[Const[C, *]] = | ||
@deprecated("Use catsDataTraverseForConst instead", "2.10.0") |
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 think we might want to override map
in catsDataTraverseForConst
, for Performance:tm:. Or, so long as we are keeping ConstFunctor
, we can extend from it to inherit the specialized implementation.
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 made it final override
because it was also overridden in ConstApplicative
- Reorder instances in `Const` systematically - Fix ambiguous `InvariantMonoidal` instance - Add `ContravariantSemigroupal` instance - Deprecate unnecessary `Functor` instance - Add `Hash` instance and `hash` method - Add `SemigroupK` and `MonoidK` instances
- Both `Traverse` and `Applicative` have a default `map` implementation - Trait linearization determines which `map` method is called - Make `map` in `ConstFunctor` final override to make sure
Const
systematicallyInvariantMonoidal
instanceContravariantSemigroupal
instanceFunctor
instanceHash
instance andhash
methodSemigroupK
andMonoidK
instances