Stylianos Gakis
02/01/2023, 3:50 PMshift
function, a code snippet is attached:
suspend fun main() {
effect<String, Int> {
shift("SHIFT ME")
}.fold({ it shouldBe "SHIFT ME" }, { fail("Computation never finishes") })
}
Here shift knows what B
(the return type) is due to it being the last in the function so it’s Int
.
When shift isn’t used at the end like that, one would need to explicitly pass something to be able to call shift, otherwise it won’t know what B
is. How is this typically supposed to be used? Is explicitly passing a type there the expected approach while calling that function? And in reality, if I am only calling shift to short-circuit, I won’t use the return value, so should it just be Unit
?
For now I realized doing just ensure(condition) { LeftType }
was what I wanted, but how about other cases?raulraja
02/01/2023, 3:52 PMraise
in 2.0 and the return type is no longer a generic <A>
representing the exit but just Nothing
raise
only cares about the left type of the effect. If you don't ascribe the type in the effect it won't be able to infer Int in the right same as your example. I think the issue would still be the same but raise no longer depends on it. Here the issue is none of your function return an Int because they all exit with failures or shiftStylianos Gakis
02/01/2023, 4:01 PM