Usually Scalaz Unapply does a pretty good job, but it seems like it breaks down here to traverseU :
scala> import scalaz._, Scalaz._, Unapply._ import scalaz._ import Scalaz._ import Unapply._ scala> val stateMonadInstance = unapplyMAB2[Monad, State, Int, Unit](IndexedStateT.stateMonad[Int]).TC stateMonadInstance: scalaz.Monad[[X]scalaz.IndexedStateT[[+X]X,Int,Int,X]] = scalaz.StateTInstances1$$anon$1@27c591e1 scala> List(1, 2, 3).traverseU((i: Int) => stateMonadInstance.pure(i)) <console>:18: error: Unable to unapply type `scalaz.IndexedStateT[[+X]X,Int,Int,Int]` into a type constructor of kind `M[_]` that is classified by the type class `scalaz.Applicative` 1) Check that the type class is defined by compiling `implicitly[scalaz.Applicative[<type constructor>]]`. 2) Review the implicits in object Unapply, which only cover common type 'shapes' (implicit not found: scalaz.Unapply[scalaz.Applicative, scalaz.IndexedStateT[[+X]X,Int,Int,Int]]) List(1, 2, 3).traverseU((i: Int) => stateMonadInstance.pure(i)) ^
The traverseS method seems to have been created as a workaround for this problem, regardless of what it is:
scala> List(1, 2, 3).traverseS((i: Int) => stateMonadInstance.pure(i)) res11: scalaz.State[Int,List[Int]] = scalaz.package$State$$anon$3@2634d0e2
But I'm trying to write a library that is common to the monad in question, so this is not very suitable. Does anyone know what kind of problem is here, what prevents it from working, and if there is a workaround that does not require a special cover for State ?
source share