You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
module foo
extern include {
js file "foo-inline.js"
}
public extern foo(fn: () -> e a): e a {
js "foo_inline"
}
fun main() {
foo { 1 }
}
And this JavaScript file foo-inline.js:
functionfoo_inline(f){returnf();}
When compiling, I get this output:
functionfoo_inline(f){returnf();}function_cps_foo(fn,_k)/* forall<a,e> (fn : () -> e a) -> e a */{returnfoo_inline(fn);}function_fast_foo(fn)/* forall<a,e> (fn : () -> e a) -> e a */{returnfoo_inline(fn);}functionfoo(fn,_k)/* forall<a,e> (fn : () -> e a) -> e a */{return((_k!==undefined)) ? _cps_foo(fn,_k) : _fast_foo(fn);}functionmain()/* () -> int */{returnfoo(function(){return1;});}
Depending on whether the effect is CPS or not, it will call either _fast_foo or _cps_foo.
However, there is a problem: _cps_foo calls foo_inline, but it doesn't pass in the _k CPS argument. This means that foo_inline cannot work for CPS effects.
This can be solved by changing _cps_foo to pass in the _k parameter.
Or alternatively it could be solved by adding in a new mechanism to specify different behavior for CPS vs non-CPS:
public extern foo(fn: () -> e a): e a {
js "foo_inline"
js cps "foo_inline_cps"
}
This would also work with inline:
public extern foo(fn: () -> e a): e a {
js inline "foo_inline(#1)"
js inline cps "foo_inline_cps(#1, #2)"
}
Personally, I prefer this solution.
The text was updated successfully, but these errors were encountered:
Consider this Koka module
foo.kk
:And this JavaScript file
foo-inline.js
:When compiling, I get this output:
Depending on whether the effect is CPS or not, it will call either
_fast_foo
or_cps_foo
.However, there is a problem:
_cps_foo
callsfoo_inline
, but it doesn't pass in the_k
CPS argument. This means thatfoo_inline
cannot work for CPS effects.This can be solved by changing
_cps_foo
to pass in the_k
parameter.Or alternatively it could be solved by adding in a new mechanism to specify different behavior for CPS vs non-CPS:
This would also work with inline:
Personally, I prefer this solution.
The text was updated successfully, but these errors were encountered: