When playing with cats, I noticed a certain behavior that I cannot explain:
import cats.implicits._ ... def wrapA[A, F[_]](v: A)(implicit F: Applicative[F]): F[A] = F.pure(v)
not a very useful method, just playing.
with full parameterization of the method or when transferring the desired instance, it obviously works fine:
val o: Option[Int] = wrapA[Int, Option](1) val o: Option[Int] = wrapA(1)(catsStdInstancesForOption)
this is not typecheck:
val o: Option[Int] = wrapA(1)
OK, TryInstances resolved before OptionInstances
trait AllInstances ... with OptionInstances ... with TryInstances with TupleInstances ...
But then why wasn't Tuple2 expected instead of Try ? TupleInstances resolve before TryInstances and define an Applicative instance. Is this an aria? Is there a specific reason for the order of instances? And although I see that the type of value does not affect implicit resolution, why doesn't it?
Cats 0.9.0, Scala 2.12.1
Thanks.
EDIT It seems that there is no Applicative instance for Tuple2 and therefore no pure , so this part of the question seems to be parsed.
source share