diverging implicit expansion problem with nested
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
Here is a simplified version of a problem I am having. The following code:
implicit class fooOps[F[_], A](foo: F[Either[String, Option[A]]]) {
import cats.instances.option._
import cats.instances.either._
import cats.syntax.nested._
def bar(implicit functor: Functor[F]): F[Either[String, Option[String]]] =
foo.nested.nested
.map(_.toString)
.value
.value
}
gives me:
Error:(33, 18) diverging implicit expansion for type cats.Functor[F]
starting with value functor
foo.nested.nested
moving the refrence to Functor[F] to the class level, ie:
implicit class fooOps[F[_]: Functor, A](foo: F[Either[String, Option[A]]]) {
def bar: F[Either[String, Option[String]]] = ???
}
gives me the same problem. Why is this? Is there any way around it?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test entry point is named. Start by reproducing the nested implicit-expansion example with the shown cats imports and inspect the compiler's resolution of Functor[F]. Done means identifying why resolution diverges and documenting a confirmed explanation or workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100