Type of a function accepting a block
argument and adding to its set of effects
#675
Replies: 1 comment 1 reply
-
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.
It's one nice way to avoid indentation. |
Beta Was this translation helpful? Give feedback.
-
I'm just starting out with koka 👋
I'm writing a function to operate on a resource, so it accepts a function parameter (
block: (resource) -> e a
) to use the resource and return anything.The acquisition of this resource requires
io
, so I figure the return type of the whole function should be<io|e> a
, which I read as "IO, plus whatever effect the block needs". This seems like it would be a pretty common idiom given koka'swith
syntax.Here's a simplified version of the code which uses an int resource. Without the acquisition using IO, it works fine:
But if I change
use-int
signature to:Then I get the error:
Thoughts:
$e
? In this context I thought it would just bee
? Is$
a qualifier for a generic type perhaps?$e
, but it wanted (expected)<io|$e>
. I thought that any effectx
would always be a subtype (sub-effect-type?) of <x|anything-else>`, so I don't understand why this doesn't match.I also tried adding a
println
to the top of theuse-int
function, like so:And the error now is:
Which seems similar, although now it's referring to
_e1
which sounds unrelated to$e
. But I don't know why the inferred effect would be$e
, shouldn't it beconsole
?Beta Was this translation helpful? Give feedback.
All reactions