I have something like
def test[F[_]: Sync: Console](counter: Int): F[Unit] =
for {
_ <- if(counter % 10000 == 0) Console[F].println(s"counter: ${counter}") else Sync[F].unit
_ <- test( counter + 1 )
} yield ()
and want to add
_ <- Temporal[F].sleep(50.milliseconds)
in the for-statements. But adding the (then neccessary) context bound : Temporal causes the compile-error Cannot resolve symbol flatMap. What is wrong with this code?
I have tried the additional parameter
(implicit T: Temporal[F])
instead of : Temporal , but get the same error.
Both
SyncandTemporalareMonad/FlatMapand this implicit ambiguity confuses how to desugar for-comprehension into a chain of.flatMap/.map.Since
Syncis now used only for.unitandTemporalalready has monadic.unit, one option is to remove the context bound: SyncAnother option is to desugar the for-comprehension manually and specify explicitly which
Monadinstance out ofSync[F],Temporal[F]is used in.flatMap