passing function error #734
-
|
When I try to write the following function: I get this error on the I fixed the error using ths declation of the function: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
|
This is a common misconception. The type of parameters specifies the "maximum" effect type of functions that can be passed in. Because the overall effect includes When you pass in a function without the So you are not "forcing" the passed function to have the Generally your function parameters will have the same effect type as the return type unless you are handling an effect, or "mask"ing an effect: https://koka-lang.github.io/koka/doc/book.html#sec-mask. While masking can allow you to get rid of the console effect in the parameter's function type, it shouldn't be used unless you have another reason for using it - especially for effects that are not user-handled like console. |
Beta Was this translation helpful? Give feedback.
-
|
I think this is one of the issues with row types, or the way they're used. I have the same issue in my programming language. The reason why this code doesn't work is because when type checking So you try to unify Intuitively, I think most users (including myself) would think that effect type of a function type should indicate the effects the function may perform. But what it actually indicates is something like: the handlers that are allowed to be handled at the call sites. Even this definition may not be 100% accurate and may be confusing to explain some examples. @TimWhiting I'd be interesting to know if you have any thoughts on this, or whether you see this as a problem. |
Beta Was this translation helpful? Give feedback.
This is a common misconception. The type of parameters specifies the "maximum" effect type of functions that can be passed in. Because the overall effect includes
console, the function passed as a parameter can also use theconsoleeffect.When you pass in a function without the
consoleeffect Koka automatically "opens" the effect type before checking it against the parameter type. It is sort of a subtyping relation.So you are not "forcing" the passed function to have the
consoleeffect. You are just saying that if a function needs fewer effects, and it is running in a context that has access to more effects, then it will still work since it will only use the effects it needs, and all of…