質問

I am trying to define this method that uses shapeless and Scalaz at the same time, however it is picking up an implicit from scalaz for the map, instead of something (an "implicit macro" perhaps? I don't even know what that is) from shapeless:

import scalaz._
import Scalaz._
import Category._
import shapeless.{Lens => _, _}
import poly._
import syntax.std.tuple._
import language.{higherKinds,implicitConversions}

/** Partitions an object which is isomorphic to a Seq, into two objects of the same type. */
def partitionIso[A,B](p: B => Boolean)(a: A)(implicit iso: A <=> Seq[B]): (A, A) =
  iso.to(a).partition(p).map(iso.from(_))

Eclipse says:

Multiple markers at this line
- Implicit arguments found: => 
 ( scalaz.Functor.Tuple2Functor )
- type mismatch; found : (Seq[B], A) required: (A, A)
- Implicit conversions found: => Tuple2MA()

How can I change this code to make it compile?

役に立ちましたか?

解決

As someone still learning Scala, I have never run across this issue (though it is the one scary thing about implicits no one ever talks about because they seem so cool), but I think you have a few options:

  • Disable the implicit you don't want by aliasing it to something like _ in an import (only works if the implicit is not in a trait) in a manner like this.
  • Override the implicit with a non-implicit method of the same name.
  • Just don't import the implicit conversion. Write your own to do the same thing if needed.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top