You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// using scala 3.1.1-RC1traitApplicative[F[_]]:extension [T<:NonEmptyTuple:Tuple.IsMappedBy[F]](t: T)
defmapN[B](f: Tuple.InverseMap[T, F] =>B):F[B] =???givenoptionApplicative:Applicative[Option] with {}
givenlistApplicative:Applicative[List] with {}
@main defapplicatives=
(Option(1), Option(2), Option(3)).mapN(_ + _ + _)
Output
println((Option(1), Option(2), Option(3)).tupled) works fine but println((Option(1), Option(2), Option(3)).mapN(_ + _ + _)) fails to compile with:
[error] ./app.scala:34:11:Found: (Option[Int], Option[Int], Option[Int])
[error] Required:?{ mapN: ? }
[error] Note that implicit extension methods cannot be applied because they are ambiguous;
[error] both objectoptionApplicative and objectlistApplicative provide an extension method `mapN` on (Option[Int], Option[Int], Option[Int])
[error] println((Option(1), Option(2), Option(3)).mapN(_ + _ + _))
[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expectation
The listApplicative instance should not conflict with optionApplicative instance because the mapN method from the list instance requires Tuple.IsMappedBy[List] evidence.
Moving the Tuple.IsMappedBy[F] constraint from the extension declaration down to each extension method and ensuring the using param list on mapN comes before the regular param list yields the expected behavior. That is, the following works fine:
Compiler version
3.1.1-RC1
Minimized code
Further minimization:
Output
println((Option(1), Option(2), Option(3)).tupled)
works fine butprintln((Option(1), Option(2), Option(3)).mapN(_ + _ + _))
fails to compile with:Expectation
The
listApplicative
instance should not conflict withoptionApplicative
instance because themapN
method from the list instance requiresTuple.IsMappedBy[List]
evidence.Moving the
Tuple.IsMappedBy[F]
constraint from the extension declaration down to each extension method and ensuring theusing
param list onmapN
comes before the regular param list yields the expected behavior. That is, the following works fine:Whereas this version has the same ambiguity error as the original:
Seems similar to #12126.
The text was updated successfully, but these errors were encountered: