Stream: beginners

Topic: Problem with missing to_hash function?


view this post on Zulip Oliver (Oct 31 2026 at 10:12):

I'm getting nowhere trying to solve a bug in my code. I keep getting:

── ✗ missing method ───────────────────────────────────────────────────────────────────────────────── Allergies.roc:29:7

This to_hash call is on a value whose type never resolved to a concrete type, so it has no to_hash method.

d = set(3)
    ^^^

Using the value somewhere that requires a specific type, or annotating it, will give it one.

What am I doing wrong? It seems to be a problem with Set.from_list(). Is it because there isn't a to_hash function for Allergen? Can I make it use a default to_hash?

My code is:

Allergies :: {}.{
    Allergen : [Eggs, Peanuts, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats]

    allergic_to : Allergen, U64 -> Bool
    allergic_to = |allergen, score| {
        set(score).contains(allergen)
    }

    set : U64 -> Set(Allergen)
    set = |score| {
        [1, 2, 4, 8, 16, 32, 64, 128].keep_if(|n| score.bitwise_and(n) > 0)
            |> List.map(
                |n| match n {
                    1 => Eggs
                    2 => Peanuts
                    4 => Shellfish
                    8 => Strawberries
                    16 => Tomatoes
                    32 => Chocolate
                    64 => Pollen
                    128 => Cats
                    _ => crash "Invalid score"
                },
            )
            |> Set.from_list()
    }

    expect {
        d = set(3)
        dbg d
        d.contains(Eggs) == Bool.True
    }
}

view this post on Zulip Anton (Oct 31 2026 at 10:19):

Hi @Oliver,
I just tried it and your code works on the latest nightly 2026-10-30, can you try that version and let me know if that solves it for you as well?

view this post on Zulip Anton (Oct 31 2026 at 10:19):

By the way, Allergen is a tag union so the compiler knows how to hash it.

view this post on Zulip Oliver (Oct 31 2026 at 10:44):

Amazing. Thank you. I should have tried that first. I was using a version from 21st Oct, but evidently something relevant has changed since then. Thank you.

view this post on Zulip Aurélien Geron (Oct 31 2026 at 20:42):

This issue was resolved a few days ago:
https://github.com/roc-lang/roc/issues/12521


Last updated: Nov 04 2026 at 18:54 UTC