propensive / mercator-old

Automatic typeclass-based abstraction over monad-like types
https://propensive.com/opensource/mercator/
Apache License 2.0
54 stars 10 forks source link

explicit instances cause ambiguous implicits #4

Closed fommil closed 6 years ago

fommil commented 6 years ago

I wanted to create an optimised, universally quantified, instance (which can be cached across the E parameter)

  implicit def mercatorDisjunction[E]: mercator.Monadic[E \/ ?] = new mercator.Monadic[E \/ ?] {
    def point[A](a: A): E \/ A = \/-(a)
    def flatMap[A, B](fa: E \/ A, f: A => E \/ B): E \/ B = fa.flatMap(f)
    def map[A, B](fa: E \/ A, f: A => B): E \/ B = fa.map(f)
  }

but using this I get

[error] /home/fommil/Projects/scalaz-deriving/examples/jsonformat/src/main/scala/jsonformat/JsMagnolia.scala:140:32: ambiguous implicit values:
[error]  both method mercatorDisjunction in object JsMagnoliaDecoder of type [E]=> mercator.Monadic[[β$0$]scalaz.\/[E,β$0$]]
[error]  and macro method monadicEvidence in package mercator of type [F[_]]=> mercator.Monadic[F]
[error]  match expected type mercator.Monadic[[+B]scalaz.\/[String,B]]
[error]           ctx.constructMonadic { p =>
[error]                                ^