Sam
08/22/2022, 3:25 PMshift return Nothing?
It’s declared as
suspend fun <B> shift(r: R): B
but it could instead be
suspend fun shift(r: R): Nothing
The reason I ask is specifically because of this use case:
var failure: MyFailure? = null
val effect = eagerEffect<MyFailure, String> {
failure?.let { shift(it) } // "Not enough information to infer type variable B"
"some result"
}
The fix is to be explicit about the Nothing type, which feels super weird:
val effect = eagerEffect<MyFailure, String> {
failure?.let { shift<Nothing>(it) }
"some result"
}raulraja
08/22/2022, 4:41 PMNothing but due to how inference worked it was causing issues. It may be possible now. Technically Nothing is more correct than any type because after shift is called all statements and code afterward is unreachable.raulraja
08/22/2022, 4:42 PMsimon.vergauwen
08/23/2022, 6:42 AMemptyList from Kotlin Std. Requiring A rather than Nothing.
IIRC, this is the recommended pattern for inference in Kotlin but I might be mistaken.Sam
08/23/2022, 7:39 AMerror(...) which isn’t generic and always returns Nothing. I can see why emptyList uses the generic, but my sense is that shift is more similar to error than to emptyList.simon.vergauwen
08/23/2022, 7:40 AMbut my sense is thatYes, very valid. We hadn't made this comparison before 🤔 Good candidate for Arrow 2.0 improvement as @raulraja said. Feel free to make a ticket for this on the Github repo so we can keep track of it 👍is more similar toshiftthan toerroremptyList
Sam
08/23/2022, 8:25 AMsimon.vergauwen
08/23/2022, 8:25 AMSam
10/10/2022, 10:21 AM