I fiddled with some basic Cats / Scalaz examples, and also go through tutorials to get a feel for it, and I hit the case, and I'm sure there is a solution.
Is it possible to call a generic function that takes a contextualized value ( F[A]
) with a Functor ( F[_] : Functor
) representation with a context <: F
? I know that Functor is type-invariant F[_]
, and I also know about existence Functor.widen
, but it seems strange that there is no way to implicitly extend my type for use in a common function.
Example in Cats (a similar example with Scalaz also exists):
import cats.instances.all._
import cats.syntax.all._
def takesAFunctor[F[_] : cats.Functor](f: F[Int]) = f.map(_ + 1)
takesAFunctor(Option(1)) // Works fine (of course)
takesAFunctor(Some(1)) // No implicit for Functor[Some]. Makes sense, but can we summon one since we have a Functor[Option]?
takesAFunctor(Some(1): Option[Int]) // Works but very verbose
Of course, calling the Functor for Parameter function is explicit and the display works as expected
Functor[Option].map(Some(1))(_ + 1)
, : , - " ", , Scala stdlib?