Type of a function accepting a block argument and adding to its set of effects
#675
-
|
I'm just starting out with koka 👋 I'm writing a function to operate on a resource, so it accepts a function parameter ( The acquisition of this resource requires Here's a simplified version of the code which uses an int resource. Without the acquisition using IO, it works fine: fun use-int(block: (int) -> e a): e a
block(55)
fun main()
use-int fn (i)
println("got: " ++ i.show)But if I change Then I get the error: Thoughts:
I also tried adding a And the error now is: Which seems similar, although now it's referring to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Yes, any effect type Let's use something other than So this is the program you are trying to write, and it is causing errors: The problem here is that If it is the former, we want to state that If you want the exceptions thrown by By the way, if the rest of the block will be indented (i.e. with i <- use-int
// Cannot throw an exception here unless I have two exception handlers
println("got: " ++ i.show)It's one nice way to avoid indentation. |
Beta Was this translation helpful? Give feedback.
Yes, any effect type
<x>would be a subtype of<x,a,b,c...>.However, with polymorphic effect type variables this changes a bit.
Let's use something other than
ioto make it a little more explicit. Let's just do exception.So this is the program you are trying to write, and it is causing errors:
The problem here is that
blockcan throw exception. (After all the variableecan unify with anything).Since it can throw an exception, which handler should handle it? The same one that catches errors thrown by
use-int? Or a different one? In other words, is the hand…