Stream: beginners

Topic: "type does not implement method"


view this post on Zulip Hubert Małkowski (Jan 31 2026 at 11:03):

When I define an ADT in app module like this:

app [main!] {pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.6/2BfGn4M9uWJNhDVeMghGeXNVDFijMfPsmmVeo6M4QjKX.tar.zst"}

import pf.Stdout

Color := [Red, Green, Blue].{
    as_str : Color -> Str
    as_str = |color| match color {
        Red => "Red"
        Green => "Green"
        Blue => "Blue"
    }
}

main! = |_args| {

    red : Color
    red = Red

    Stdout.line!("My favourite color is ${red.as_str()}")
    Ok({})
}

I get this error when I try to run it (it compiles - this runtime error):

Roc crashed: Color does not implement as_str

However when I move Color definition to seperate Color.roc file then everything works.

Is this intended behavior? Do member methods only work when a type is imported from an external module, or am I missing some syntax requirement for local type definitions?

view this post on Zulip Luke Boswell (Jan 31 2026 at 11:21):

It should work, so a bug I think.

view this post on Zulip Hubert Małkowski (Jan 31 2026 at 11:32):

Ok, then I'll report it on github :)

view this post on Zulip Hubert Małkowski (Jan 31 2026 at 11:37):

https://github.com/roc-lang/roc/issues/9123


Last updated: Feb 20 2026 at 12:27 UTC