Stream: beginners

Topic: disambiguating static dispatch methods from struct fields


view this post on Zulip Victor Menge (Dec 23 2025 at 15:35):

hey!
been following roc for years, and really impressed with some of the changes done here.

recently with the new compiler, my understanding is that when we use . after a variable on the body of a function following with what seems like a method call like so:

foo = |x| {
  x.bar("aaa")
}

that the compiler will infer this to be a method implemented for that type.

if x was a struct, that had a closure called bar inside it, how would i write this function instead?

view this post on Zulip Richard Feldman (Dec 23 2025 at 16:22):

you just need some parens! (x.bar)("aaa")

view this post on Zulip Johannes Maas (Nov 22 2026 at 06:02):

Just for more data points, it's solved for me: I have stumbled into the same issue.

After some experimentation, I landed on this "workaround". The context was a harness for Advent of Code, similar to https://github.com/lukewilliamboswell/aoc-template.

Harness := { solve_puzzle : Str -> Bool }.{
    run_solution : Harness, Str -> Bool
    run_solution = |harness, input| {
        # Do additional things like handling the output and measuring runtime.

        harness.solve_puzzle(input)
        # This solve_puzzle method is being called on a value whose type doesn't have that method.
        #        harness.solve_puzzle(input)
        #                ^^^^^^^^^^^^
        # The value's type, which does not have a method named solve_puzzle, is:
        #  { solve_puzzle: Str -> Bool }

        # Workaround:
        solve_puzzle = harness.solve_puzzle
        solve_puzzle(input)
    }
}

I have not thought of putting in extra parens. I think I prefer the extra parens over a variable, though they do look a bit weird to me. This works well for me though.

But I'm curious: Is there perhaps a better representation that avoids this slight issue in the above case?


Last updated: Nov 26 2026 at 20:35 UTC