Cats-effect: Add LiftIO to ce3

Created on 22 Jul 2020  Â·  11Comments  Â·  Source: typelevel/cats-effect

We should restore LiftIO, but in the core module and extending Async.

CE 3 good first issue

All 11 comments

I'd like to work on this.

It's yours!

@djspiewak Please correct me if I'm wrong. The IO#to method uses an implicit F: Effect[F] in order to use the F#to in the implementation. Does that mean that LiftIO needs to extend Effect instead of Async? If not, how can I work around this? Thanks.

Hmm, I don't think you need to worry about any of that at all. To be clear, the definition of LiftIO should be something like this:

trait LiftIO[F[_]] extends Async[F] {
  def liftF[A](ioa: IO[A]): F[A]
}

I don't think you have to worry about to at all with that. This should be definable for anything that has a liftF (e.g. OptionT[IO, A] would have a LiftIO instance, defined by the OptionT.liftF function).

As a note, if it's easier, I think it's actually okay if we just have LiftIO be an orphan typeclass, not extending Async at all. The existing LiftIO doesn't.

Looking at the CE2 implementation of IO#to, it uses a LiftIO, but in CE3 it's Effect. Does that even matter?

Edit:
This also prevents me from implementing LiftIO.liftK.

Looking at the CE2 implementation of IO#to, it uses a LiftIO, but in CE3 it's Effect. Does that even matter?

Ah! So the use of LiftIO in ce2's IO#to is a historical artifact. The implementation in CE3 uses Effect, and that's exactly what it needs to use. :-) LiftIO means something different than "you can convert an IO to this". It actually means "you can embed an IO within this". So it's more about monad transformers.

So does that mean I should implement LiftIO.liftK by demanding an Effect[F]?

So does that mean I should implement LiftIO.liftK by demanding an Effect[F]?

Nope! You would just implement each instance on a one-off basis. For example, here's one for OptionT:

object LiftIO {
  // ...
  implicit def liftIOForOptionT[F[_]]: LiftIO[OptionT[F, *]] =
    new LiftIO[OptionT[F, *]] {
      val liftK = OptionT.liftK[F]
    }
}

Something like that!

Nevermind, I just got confused by the changes to IO#to. Thanks for taking the time to explain everything!

Again, this issue wasn't automatically closed...

So weird! GitHub must have changed something… :-/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jchapuis picture jchapuis  Â·  6Comments

ronanM picture ronanM  Â·  5Comments

kubukoz picture kubukoz  Â·  6Comments

Daenyth picture Daenyth  Â·  3Comments

RaasAhsan picture RaasAhsan  Â·  4Comments