Stream: bugs

Topic: ✔ Compiler mixing up tasks and effectful functions


view this post on Zulip Tanner Nielsen (Dec 01 2024 at 16:36):

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

view this post on Zulip Tanner Nielsen (Dec 01 2024 at 16:38):

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

view this post on Zulip Eli Dowling (Dec 01 2024 at 16:39):

Hey, I just fixed this a few hours ago :)

view this post on Zulip Eli Dowling (Dec 01 2024 at 16:39):

you can build the latest version of roc from source if you like or wait for the next nightly

view this post on Zulip Eli Dowling (Dec 01 2024 at 16:40):

see this pr:
https://github.com/roc-lang/roc/pull/7285

view this post on Zulip Tanner Nielsen (Dec 01 2024 at 16:40):

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

view this post on Zulip Eli Dowling (Dec 01 2024 at 16:40):

no worries, good luck. I'll check tomorrow to see how you went :)

view this post on Zulip Tanner Nielsen (Dec 01 2024 at 16:46):

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!

view this post on Zulip Notification Bot (Dec 01 2024 at 16:46):

Tanner Nielsen has marked this topic as resolved.

view this post on Zulip Eli Dowling (Dec 01 2024 at 18:26):

Hell yeah, the best errors are already fixed errors!


Last updated: Jul 06 2025 at 12:14 UTC