Question: implementing Checker[Task]
I'm using monix' Task instead of cats' IO in my Transactor. Nowadays monix also uses cats in the background. It works, but I'm not sure whether this is a good idea in the first place.
val transactor: Aux[Task, Unit] = Transactor.fromDriverManager[Task](
cfg.driver,
cfg.url,
cfg.user,
cfg.password
)
As next I would typecheck the queries with scalatest. Found an IOChecker and because of Task wanted to implement the TaskChecker, replacing IO with Task like here:
import cats.effect.Effect
import doobie.scalatest.Checker
import monix.eval.Task
/** Implementation of Checker[IO] */
trait TaskChecker extends Checker[Task] {
self: org.scalatest.Assertions =>
val M: Effect[Task] = implicitly
}
but becoming cryptic error message:
[error] ..\TaskChecker.scala:10:25: ambiguous implicit values:
[error] both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String]
[error] and method $conforms in object Predef of type [A]=> A <:< A
[error] match expected type T
[error] val M: Effect[Task] = implicitly
[error] ^
Is it doable at all what I want or should I better stick with IO?
May be @alexandru ?
Sorry if asked too much.
doobie, doobie-scalatest: "0.5.3 monix: "3.0.0-RC1"
Predef.implicitly doesn't always give correct error message. You can get more precise one by manually specifying the type parameter like implicitly[Effect[Task]]
The actual problem is that Task doesn't have an Effect instance by default. You can create a CatsEffectForTask: https://github.com/monix/monix/blob/v3.0.0-RC1/monix-eval/shared/src/main/scala/monix/eval/instances/CatsEffectForTask.scala#L41-L42
Note that the constructor requires additional Task.Options in the current master.
Effect is not very generic as a type class. Once you work with Effect, you effectively work with cats.effect.IO, hence the extra restriction that Effect[Task] requires.
The new Cats-Effect has a really potent Async and Concurrent that removes the need for Effect in many cases. The FS2 guys made great progress in updating the code base to no longer be dependent on Effect and there are few legitimate reasons for why Effect is still needed.
Unfortunately version 1.0.0 of Cats-Effect has been delayed repeatedly due to our attempts to get it right. On Monday we are releasing RC3 and hopefully 1.0.0 will follow in 2 weeks after that. See the milestones here: https://github.com/typelevel/cats-effect/milestones
@alexandru thanks for the update! Yeah I only use Effect because fs2 wants it here and there.