Thanks, that's really rather amazingly cool. Do you mind if I use this in a talk I'm giving in March?
In reality my problem is more complicated because I have the following
trait Ev
trait SubEv1 extends Ev
trait SubEv2 extends Ev
and the "MyStuff" is going to be a List[SubEv1] or a List[SubEv2]. Essentially I have this helper method:
scala> object EvHelpers { def mapped[T <: Ev](evs: Traversable[T]): Map[Int, T] = ??? }
defined module EvHelpers
And I want to decorate any F[CC[T]] for F: Functor, CC <: traversable and T <: Ev, with a "mapped" method. So I have to pass a type T thru:
scala> final class TraversableEvFunctorOps[F[_], A, T <: Ev](self: F[A], F: Functor[F]) {
| def mapped(implicit A: A => Traversable[T]): F[Map[Int, T]] = F.map(self)(a => EvHelpers.mapped(A(a)))
| }
defined class TraversableEvFunctorOps
scala> implicit def traversableEvFunctorOps[FA, T <: Ev](fa: FA)(implicit F: Unapply[Functor, FA]) = new TraversableEvFunctorOps[F.M, F.A, T](F(fa),
F.TC)
traversableEvFunctorOps: [FA, T <: Ev](fa: FA)(implicit F: scalaz.Unapply[scalaz.Functor,FA])TraversableEvFunctorOps[F.M,F.A,T]
But scala doesn;t seem to be able to infer T here
scala> some(List(new SubEv1 {} ))
res11: Option[List[SubEv1]] = Some(List($anon$1@296e2712))
scala> lazy val x = res11.mapped
<console>:19: error: No implicit view available from List[SubEv1] => Traversable[T].
lazy val x = res11.mapped
^
I've also tried using implicit conforms on T:
scala> object EvHelpers { def mapped[T](evs: Traversable[T])(implicit t: T <:< Ev): Map[Int, T] = ??? }
defined module EvHelpers
scala> final class TraversableEvFunctorOps[F[_], A, T](self: F[A], F: Functor[F])(implicit t: T <:< Ev) {
| def mapped(implicit A: A => Traversable[T]): F[Map[Int, T]] = F.map(self)(a => EvHelpers.mapped[T](A(a)))
| }