Stream: ideas

Topic: effectful expect and embedding Files


view this post on Zulip removewingman (Sep 09 2026 at 08:09):

I find myself sometimes wanting to test effectful functions in roc, but as far as I know expect's should be pure.

── ✗ effectful expect ─────────────── /home/rw/media/repos/roc/plainaipha/pa2html/lib/Gnuplot.roc:27:3

This expect performs an effect while evaluating its condition.

expect {
_ = gnuplot!([])
True
}

Keep expect conditions pure, and test effectful behavior from a function body instead.

So I am suggesting to introduce a new keyword: expect!which allows effectful testing and runs every expect! as it's own small main function . This would be consistent with naming in roc, because of the: !.
One could also introduce a new cli arg, to only run these tests on demand or something, like roc test --with-effectful or roc test-effectful.

In addition something similar to @embedFile, which evaluates a file at compile time and puts it content into the binary would be really helpful. Maybe this could be an keyword e.g. embedFile, imo this would be worth. I do not know if there is any meta programming planned, tho.

What do you think?

view this post on Zulip Anton (Sep 09 2026 at 13:08):

We have given some thought to the testing of effectful functions, is there a design doc for this @Richard Feldman?

view this post on Zulip Richard Feldman (Sep 09 2026 at 14:37):

I don't think there's a doc, but it's definitely planned for after 0.1.0 :smile:

view this post on Zulip Richard Feldman (Sep 09 2026 at 14:37):

basically we need to introduce a way for platforms to specify "here is how to run an effectful function just for testing purposes" and there are a bunch of design questions in there that need to be sorted out

view this post on Zulip Richard Feldman (Sep 09 2026 at 14:37):

and I don't want to block 0.1.0 on them

view this post on Zulip Niclas Ahden (Sep 09 2026 at 20:52):

My workaround while waiting for built-in effectful tests in Roc is: https://github.com/niclas-ahden/roc-spec

view this post on Zulip removewingman (Sep 09 2026 at 21:33):

Good to know that it is planned, nice.

What about embed Files, is this a feature that could be introduced before 0.1.0?

view this post on Zulip Luke Boswell (Sep 09 2026 at 21:39):

You can embed a file at compile time using import statements

view this post on Zulip Luke Boswell (Sep 09 2026 at 21:40):

Here is an example https://github.com/lukewilliamboswell/roc-ray/blob/263383ff67f1b2b06e937387b9c4d4e71c7fa292/examples/live_plot/main.roc#L17


Last updated: Sep 24 2026 at 15:59 UTC