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

Issue 2608 - Ambiguous implicit values for Functor[Kleisli[F, A, ?]] #2618

Merged
merged 1 commit into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,32 +291,35 @@ sealed abstract private[data] class KleisliInstances4 extends KleisliInstances5
implicit def catsDataSemigroupKForKleisli[F[_], A](implicit F0: SemigroupK[F]): SemigroupK[Kleisli[F, A, ?]] =
new KleisliSemigroupK[F, A] { def F: SemigroupK[F] = F0 }

implicit def catsDataApplicativeErrorForKleisli[F[_], E, A](
implicit F0: ApplicativeError[F, E]
): ApplicativeError[Kleisli[F, A, ?], E] =
new KleisliApplicativeError[F, A, E] { def F: ApplicativeError[F, E] = F0 }

implicit def catsDataFlatMapForKleisli[F[_], A](implicit FM: FlatMap[F]): FlatMap[Kleisli[F, A, ?]] =
new KleisliFlatMap[F, A] { def F: FlatMap[F] = FM }

}

sealed abstract private[data] class KleisliInstances5 extends KleisliInstances6 {

implicit def catsDataApplicativeErrorForKleisli[F[_], E, A](
implicit F0: ApplicativeError[F, E]
): ApplicativeError[Kleisli[F, A, ?], E] =
new KleisliApplicativeError[F, A, E] { def F: ApplicativeError[F, E] = F0 }
}

sealed abstract private[data] class KleisliInstances6 extends KleisliInstances7 {
implicit def catsDataApplicativeForKleisli[F[_], A](implicit A: Applicative[F]): Applicative[Kleisli[F, A, ?]] =
new KleisliApplicative[F, A] { def F: Applicative[F] = A }
}

sealed abstract private[data] class KleisliInstances6 extends KleisliInstances7 {
sealed abstract private[data] class KleisliInstances7 extends KleisliInstances8 {
implicit def catsDataApplyForKleisli[F[_], A](implicit A: Apply[F]): Apply[Kleisli[F, A, ?]] =
new KleisliApply[F, A] { def F: Apply[F] = A }
}

sealed abstract private[data] class KleisliInstances7 extends KleisliInstances8 {
sealed abstract private[data] class KleisliInstances8 extends KleisliInstances9 {
implicit def catsDataDistributiveForKleisli[F[_], R](implicit F0: Distributive[F]): Distributive[Kleisli[F, R, ?]] =
new KleisliDistributive[F, R] with KleisliFunctor[F, R] { implicit def F: Distributive[F] = F0 }
}

sealed abstract private[data] class KleisliInstances8 {
sealed abstract private[data] class KleisliInstances9 {
implicit def catsDataFunctorForKleisli[F[_], A](implicit F0: Functor[F]): Functor[Kleisli[F, A, ?]] =
new KleisliFunctor[F, A] { def F: Functor[F] = F0 }
}
Expand Down
5 changes: 5 additions & 0 deletions tests/src/test/scala/cats/tests/KleisliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class KleisliSuite extends CatsSuite {
checkAll("Contravariant[Kleisli[Option, ?, Int]]",
SerializableTests.serializable(Contravariant[Kleisli[Option, ?, Int]]))

test("Functor[Kleisli[F, Int, ?]] is not ambiguous when an ApplicativeError and a FlatMap are in scope for F") {
def shouldCompile1[F[_]: ApplicativeError[?[_], E]: FlatMap, E]: Functor[Kleisli[F, Int, ?]] =
Functor[Kleisli[F, Int, ?]]
}

test("local composes functions") {
forAll { (f: Int => Option[String], g: Int => Int, i: Int) =>
f(g(i)) should ===(Kleisli.local[Option, String, Int](g)(Kleisli(f)).run(i))
Expand Down