Is it possible for a platform effect to take in a roc closure as a callback?
I see this example has a todo to figure out how to call the closure pointer
Could the roc__mainForHost_0_caller
work to call arbitrary closures or would that only work for main? Would manually boxing the closure help?
Theoretically
Though, I wouldn't expect it to work easily currently
That said, it may not generate in an exposed manner unless the closure is exposed via the mainForHost.
A lot of the changes to platforms that are coming are related to this. In the new form, the standard will be that all effects take a continuation.
Anyway, what is your goal? That may give me a better idea of what could be done.
The use case i have is to try to hook up roc code to this rust property based testing lib
it wants all the tests to be in a closure like
runner.run(<value generators> |<generated vals>| {
// test logic that would call the closure
}).unwrap();
So in an ideal world the effect func would be something like
fn roc_fx_run_pbt(val_gen: Foo, testFn: RocFn) {
let mut runner = TestRunner::default();
runner.run(val_gen, |generated| {
testFn(generated)
}).unwrap();
}
I think i could probably get away with having my testing platform take in a list of tests in the mainForHost and just repeatedly call main over and over with different generated values to run the tests multiple times
I'm a bit confused, why would that be an effect? Isn't that the main goal of the platform. Why not just make main be the function you are property testing?
I wonder if it would currently work to just have main return a list of closures
Not actually sure.
I was hoping to have one 1 roc app that would run many different pbt tests so it would be something like
main =
_ <- pf.PBT <some type to specify generator> (\<gen vals> -> test1)
_ <- pf.PBT <some type to specify diff generator> (\<gen vals2> -> test2)
so the list of closures approach would probably be fine. Ill mess around with that
I would say, try it, and see what llvm ir we generate (mono ir might also be useful to look at).
That is the only way to tell if this might work currently or not
But I do think it is totally untested.
My gut feeling is that it will generate something useless cause we won't actually expose the functions. So you will have a closure capture with no function to actually pass the data to.
On the otherhand, I know that main returning a record of closures works, so maybe a list of closures could work too. Though it is also untested.
John Murray said:
Is it possible for a platform effect to take in a roc closure as a callback?
technically yes, but in practice the glue for it isn't there yet - @Folkert de Vries and @Brendan Hansknecht and I have been working on this for quite awhile
once we have "effect interpreters" working, this will work too :big_smile:
because that's all about passing Roc closures to the host
Is there a desgin/plan doc for effect interpreters? I've heard that mentioned a few times so curious what it looks like
Thought the doc would be linked here, but guess not... https://www.roc-lang.org/plans
We should add details here when we collect docs and such
oh yeah we should also remove "Inspect
Inference" from that page since it exists now! :smiley:
Last updated: Jul 05 2025 at 12:14 UTC