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

WriterTInstances: insufficient prioritization #3394

Merged
merged 1 commit into from
Apr 13, 2020
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
44 changes: 23 additions & 21 deletions core/src/main/scala/cats/data/WriterT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,6 @@ object WriterT extends WriterTInstances with WriterTFunctions with WriterTFuncti
}

sealed abstract private[data] class WriterTInstances extends WriterTInstances0 {
implicit def catsDataCommutativeMonadForWriterT[F[_], L](
implicit F: CommutativeMonad[F],
L: CommutativeMonoid[L]
): CommutativeMonad[WriterT[F, L, *]] =
new WriterTMonad[F, L] with CommutativeMonad[WriterT[F, L, *]] {
implicit val F0: Monad[F] = F
implicit val L0: Monoid[L] = L
}

implicit def catsDataTraverseForWriterTId[L](implicit F: Traverse[Id]): Traverse[WriterT[Id, L, *]] =
catsDataTraverseForWriterT[Id, L](F)

Expand All @@ -367,6 +358,17 @@ sealed abstract private[data] class WriterTInstances extends WriterTInstances0 {
}

sealed abstract private[data] class WriterTInstances0 extends WriterTInstances1 {
implicit def catsDataCommutativeMonadForWriterT[F[_], L](
implicit F: CommutativeMonad[F],
L: CommutativeMonoid[L]
): CommutativeMonad[WriterT[F, L, *]] =
new WriterTMonad[F, L] with CommutativeMonad[WriterT[F, L, *]] {
implicit val F0: Monad[F] = F
implicit val L0: Monoid[L] = L
}
}

sealed abstract private[data] class WriterTInstances1 extends WriterTInstances2 {

implicit def catsDataTraverseForWriterT[F[_], L](implicit F: Traverse[F]): Traverse[WriterT[F, L, *]] =
new WriterTTraverse[F, L] {
Expand All @@ -377,7 +379,7 @@ sealed abstract private[data] class WriterTInstances0 extends WriterTInstances1
catsDataFoldableForWriterT[Id, L](F)
}

sealed abstract private[data] class WriterTInstances1 extends WriterTInstances2 {
sealed abstract private[data] class WriterTInstances2 extends WriterTInstances3 {
implicit def catsDataMonadErrorForWriterT[F[_], L, E](implicit F: MonadError[F, E],
L: Monoid[L]): MonadError[WriterT[F, L, *], E] =
new WriterTMonadError[F, L, E] {
Expand Down Expand Up @@ -428,7 +430,7 @@ sealed abstract private[data] class WriterTInstances1 extends WriterTInstances2
}
}

sealed abstract private[data] class WriterTInstances2 extends WriterTInstances3 {
sealed abstract private[data] class WriterTInstances3 extends WriterTInstances4 {
implicit def catsDataMonadForWriterTId[L: Monoid]: Monad[WriterT[Id, L, *]] =
catsDataMonadForWriterT[Id, L]

Expand All @@ -442,7 +444,7 @@ sealed abstract private[data] class WriterTInstances2 extends WriterTInstances3
catsDataComonadForWriterT[Id, L](F)
}

sealed abstract private[data] class WriterTInstances3 extends WriterTInstances4 {
sealed abstract private[data] class WriterTInstances4 extends WriterTInstances5 {
implicit def catsDataMonadForWriterT[F[_], L](implicit F: Monad[F], L: Monoid[L]): Monad[WriterT[F, L, *]] =
new WriterTMonad[F, L] {
implicit val F0: Monad[F] = F
Expand All @@ -458,12 +460,12 @@ sealed abstract private[data] class WriterTInstances3 extends WriterTInstances4
catsDataCoflatMapForWriterT[Id, L]
}

sealed abstract private[data] class WriterTInstances4 extends WriterTInstances5 {
sealed abstract private[data] class WriterTInstances5 extends WriterTInstances6 {
implicit def catsDataFlatMapForWriterTId[L: Semigroup]: FlatMap[WriterT[Id, L, *]] =
catsDataFlatMapForWriterT2[Id, L]
}

sealed abstract private[data] class WriterTInstances5 extends WriterTInstances6 {
sealed abstract private[data] class WriterTInstances6 extends WriterTInstances7 {
implicit def catsDataFlatMapForWriterT1[F[_], L](implicit F: FlatMap[F], L: Monoid[L]): FlatMap[WriterT[F, L, *]] =
new WriterTFlatMap1[F, L] {
implicit val F0: FlatMap[F] = F
Expand All @@ -476,7 +478,7 @@ sealed abstract private[data] class WriterTInstances5 extends WriterTInstances6
}
}

sealed abstract private[data] class WriterTInstances6 extends WriterTInstances7 {
sealed abstract private[data] class WriterTInstances7 extends WriterTInstances8 {
implicit def catsDataApplicativeErrorForWriterT[F[_], L, E](implicit F: ApplicativeError[F, E],
L: Monoid[L]): ApplicativeError[WriterT[F, L, *], E] =
new WriterTApplicativeError[F, L, E] {
Expand All @@ -485,7 +487,7 @@ sealed abstract private[data] class WriterTInstances6 extends WriterTInstances7
}
}

sealed abstract private[data] class WriterTInstances7 extends WriterTInstances8 {
sealed abstract private[data] class WriterTInstances8 extends WriterTInstances9 {
implicit def catsDataAlternativeForWriterT[F[_], L](implicit F: Alternative[F],
L: Monoid[L]): Alternative[WriterT[F, L, *]] =
new WriterTAlternative[F, L] {
Expand All @@ -501,7 +503,7 @@ sealed abstract private[data] class WriterTInstances7 extends WriterTInstances8
}
}

sealed abstract private[data] class WriterTInstances8 extends WriterTInstances9 {
sealed abstract private[data] class WriterTInstances9 extends WriterTInstances10 {
implicit def catsDataMonoidKForWriterT[F[_], L](implicit F: MonoidK[F]): MonoidK[WriterT[F, L, *]] =
new WriterTMonoidK[F, L] {
implicit val F0: MonoidK[F] = F
Expand All @@ -519,7 +521,7 @@ sealed abstract private[data] class WriterTInstances8 extends WriterTInstances9
}
}

sealed abstract private[data] class WriterTInstances9 extends WriterTInstances10 {
sealed abstract private[data] class WriterTInstances10 extends WriterTInstances11 {
implicit def catsDataSemigroupKForWriterT[F[_], L](implicit F: SemigroupK[F]): SemigroupK[WriterT[F, L, *]] =
new WriterTSemigroupK[F, L] {
implicit val F0: SemigroupK[F] = F
Expand All @@ -536,22 +538,22 @@ sealed abstract private[data] class WriterTInstances9 extends WriterTInstances10
new WriterTInvariant[F, L] { implicit val F = F0 }
}

sealed abstract private[data] class WriterTInstances10 extends WriterTInstances11 {
sealed abstract private[data] class WriterTInstances11 extends WriterTInstances12 {
implicit def catsDataApplyForWriterT[F[_], L](implicit F: Apply[F], L: Semigroup[L]): Apply[WriterT[F, L, *]] =
new WriterTApply[F, L] {
implicit val F0: Apply[F] = F
implicit val L0: Semigroup[L] = L
}
}

sealed abstract private[data] class WriterTInstances11 extends WriterTInstances12 {
sealed abstract private[data] class WriterTInstances12 extends WriterTInstances13 {
implicit def catsDataComonadForWriterT[F[_], L](implicit F: Comonad[F]): Comonad[WriterT[F, L, *]] =
new WriterTComonad[F, L] {
implicit val F0: Comonad[F] = F
}
}

sealed abstract private[data] class WriterTInstances12 {
sealed abstract private[data] class WriterTInstances13 {
implicit def catsDataCoflatMapForWriterT[F[_], L](implicit F: Functor[F]): CoflatMap[WriterT[F, L, *]] =
new WriterTCoflatMap[F, L] {
implicit val F0: Functor[F] = F
Expand Down
5 changes: 5 additions & 0 deletions tests/src/test/scala/cats/tests/WriterSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ class WriterSuite extends CatsSuite {
result.writer(log) should ===(Writer(log, result))
}
}

test("catsDataCommutativeMonadForWriterT and catsDataTraverseForWriterTId instances are not ambiguous") {
import cats.Functor
Functor[Writer[Int, *]]
}
}