Skip to content

Conversation

@mark-gerarts
Copy link
Contributor

Hi, I was toying around with the language and stumbled upon a broken code sample on the homepage, for algebraic effects:

import java.time.LocalDateTime

eff HourOfDay {
    def getCurrentHour(): Int32
}

def greeting(): String \ {HourOfDay} = 
    let h = HourOfDay.getCurrentHour();
    if (h <= 12) "Good morning"
    else if (h <= 18) "Good afternoon"
    else "Good evening"

def main(): Unit \ IO = 
    run {
        println(greeting())
    } with HourOfDay {
        def getCurrentHour(_, resume) = 
            let dt = LocalDateTime.now();
            resume(dt.getHour())
    }

Trying to run this yields an error:

$ flix main.flix
-- Resolution Error -------------------------------------------------- main.flix

>> Undefined name 'HourOfDay'.

16 |     } with HourOfDay {
                ^^^^^^^^^
                name not found


~ Want to help improve this error message? Create a PR on GitHub:
  https://flix.dev/go/language/errors/ResolutionError.scala#L770
  
... and so on

Reading the documentation it seems that this has to be with handler HourOfDay instead of simply with HourOfDay. Changing this makes the example compile. I might be missing something ofcourse, since I lack experience with the language.

@magnus-madsen magnus-madsen changed the title Add missing handler keyword in effect example fix: add missing handler keyword in effect example Nov 27, 2025
@magnus-madsen
Copy link
Member

Hi @mark-gerarts and thanks! I have merged the PR-- but the change will not show up until a later time when the website is deployed.

@magnus-madsen magnus-madsen merged commit 2114b69 into flix:master Nov 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants