Type inference in kyo vs mtl
Article that references this page: Environment Functions
Type inference is far stronger in kyo than in mtl, because we’re not doing a lot of value stacking. We only ever operate within one monad kyo.<, and that monad does compose with itself (as all monads do). It’s just monads don’t compose with each other.
Imagine we have Either[String, Int] and IO[Int], these don’t compose:
| |
To work together, we need to stack the monads with EitherT:
| |
EitherT[IO, String, Int] cannot be inferred here, because EitherT.fromEither does not have enough information to know what monad it’s transforming. It can infer a String error channel and Int success channel, but nothing about that expression says that it’ll operate over IO. The next expression would, but inference cannot span across two expressions.
in kyo, we don’t run into this problem:
| |
Int < (Abort[String] & Async) is inferred successfully. This is because numOrAbortString has a totally known type, and flatMap in kyo combines effects within the single kyo.< monad.