phldavies
05/17/2025, 7:59 PMimport arrow.core.raise.Raise
import arrow.core.raise.either
context(r: Raise<String>)
fun doSomething(): Unit = TODO()
context(r: Raise<Int>)
fun doSomething(): Unit = TODO()
fun main() {
either<String, Unit> {
either<Int, Unit> {
doSomething() // Overload resolution ambiguity between candidates:
// context(r: Raise<String>) fun doSomething(): Unit
// context(r: Raise<Int>) fun doSomething(): Unit
}
}
}
whereas declaring with
fun Raise<String>.doSomething(): Unit = TODO()
fun Raise<Int>.doSomething(): Unit = TODO()
resolves correctly - but this doesn't work for cases where you already have a receiver, obviously.
Even labelling the closest either
with intRaise@{
and wrapping with context(this@intRaise) { doSomething() }
doesn't resolve it.
Neither does attempting to use a contextual alternative either
constructor:
inline fun <Error, A> either(block: context(Raise<Error>) () -> A): Either<Error, A> = arrow.core.raise.either(block)
Youssef Shoaib [MOD]
05/17/2025, 9:45 PMphldavies
05/18/2025, 11:26 AMensureNotNull
will fail to resolve without explicit type parameter to disambiguate when used with nested/multiple contexts)Alejandro Serrano.Mena
05/19/2025, 6:33 AMAlejandro Serrano.Mena
05/19/2025, 6:35 AMphldavies
05/19/2025, 8:33 AMwithError
or nested recover
etc will be awkward to use.Alejandro Serrano.Mena
05/19/2025, 8:37 AMeither
, option
, and all those runners still introduce Raise
as a receiver, so the member version would be preferredAlejandro Serrano.Mena
05/19/2025, 8:38 AMwithError
and recover
also have additional type arguments which can be used to guide the resolutionAlejandro Serrano.Mena
05/19/2025, 8:39 AMphldavies
05/19/2025, 8:59 AMcontext(Raise<Response>, Raise<RequestError>) RoutingContext.() -> Unit
lambda - I can see a lot of users wanting to have custom scope functions that provide Raise
via context. It's not unworkable with explicit type args though: https://github.com/tKe/arrow/pull/2/commits/1a891a3f89bdfbddeb9e1b88331337288f145165#diff-ae4a65448c25309856d1b62cf[…]61a7a7ff0ceda7d319ec1388b6L124CLOVIS
06/03/2025, 2:53 PMthis is if we were to replace everything with parameters; butBut is that a good thing? Will future APIs continue to have,either
, and all those runners still introduceoption
as a receiver, so the member version would be preferredRaise
Raise
as a receiver? To me, it seems new APIs should use context parameters, as those better describe what Raise
is.