I'm 90% sure this a valid use of purity inference:
module [Func, pure, effect, execute!]
Func a b := [
Pure (a -> b),
Effectful (a => b),
]
pure : (a -> b) -> Func a b
pure = \f ->
@Func (Pure f)
effect : (a => b) -> Func a b
effect = \f! ->
@Func (Effectful f!)
execute! : Func a b, a => b
execute! = \@Func func, input ->
when func is
Pure f -> f input
Effectful f! -> f! input
But the compiler complains about two places:
TYPE MISMATCH
Something is off with the body of the `effect` definition:
12│ effect : (a => b) -> Func a b
13│> effect = \f! ->
14│> @Func (Effectful f!)
This `await` call produces:
Task c b
But the type annotation on `effect` says it should be:
Func a b
UNRECOGNIZED NAME
Nothing is named `f` in this scope.
20│ Effectful f! -> f! input
^^^^^^^^
Did you mean one of these?
f!
U8
Eq
I8
Note this is just a minimum reprex of an issue I'm having in a larger piece of code, so it's a bit contrived
Hey, I just fixed this a few hours ago :)
you can build the latest version of roc from source if you like or wait for the next nightly
see this pr:
https://github.com/roc-lang/roc/pull/7285
Awesome, thanks! Sorry if I missed this somewhere in another thread. I'll try to verify that this works with the latest version and resolve the thread if it does
no worries, good luck. I'll check tomorrow to see how you went :)
I built roc from the main
branch, ran roc check
against this file, and there are 0 errors and 0 warnings. Looks like it works. Thanks!
Tanner Nielsen has marked this topic as resolved.
Hell yeah, the best errors are already fixed errors!
Last updated: Jul 06 2025 at 12:14 UTC