Inconsistent `ApplicativeError` behaviour for `OptionT[F[_], A]` / `EitherT[F[_], A, B]` if `F[_]` also has an `ApplicativeError` instance
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
For example, if F[_] is Either[Throwable, *], there would exist 2 instances of ApplicativeError for OptionT[Either[Throwable, *], *]:
ApplicativeError[OptionT[Either[Throwable, *], *], Throwable] // higher priority instance derived from `F[_]`
ApplicativeError[OptionT[Either[Throwable, *], *], Unit] // default instance for all `OptionT`
The instance derived from F[_] would be higher in priority and this would result in inconsistency with the default behaviour (when F[_] does not have an ApplicativeError instance), e.g.:
import cats.implicits._
import cats.{Applicative, ApplicativeError, Monoid}
import cats.data.OptionT
def handleErrorWithMonoidEmpty[F[_], A, E: ApplicativeError[F, *]](fa: F[A])(implicit A: Monoid[A]) = fa.handleError(_ => A.empty)
// if `F[_]` is `List`, it handles `None` as error
handleErrorWithMonoidEmpty(OptionT.none[List, Int]) //OptionT(List(Some(0)))
// if `F[_]` is `Either[Throwable, *]`, it handles for `Throwable` instead
handleErrorWithMonoidEmpty(OptionT.none[Either[Throwable, *], Int]) //OptionT(Right(None))
handleErrorWithMonoidEmpty(new Throwable("throw").raiseError[OptionT[Either[Throwable, *], *], Int]) //OptionT(Right(Some(0)))
The same issue exist for EitherT:
The instance priorities are reversed for EitherT:
ApplicativeError[EitherT[Either[Throwable, *], String, *], Throwable]
ApplicativeError[EitherT[Either[Throwable, *], String, *], String] //this would be higher in priority
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
Start by inspecting the ApplicativeError instances for OptionT and EitherT, using the conflicting type examples in the issue to trace instance priority and behavior. Done means the chosen instances behave consistently whether the underlying F has an ApplicativeError instance or not, including the OptionT and EitherT cases described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100