I have a an opaque type like this:
## A number in the range 1-9, inclusive.
Number := I8 implements [
Eq { isEq },
]
isEq : Number, Number -> Bool
isEq = \@Number a, @Number b -> a == b
Do I remember correctly that there is a way to auto-derive abilities? If not, how would I go about implementing Hash
for this type? (I want to put it in a Set
)
Auto-derive is for non-opaque types. I don't think we have a way to enable an opaque type to use the auto-derived implementation. So a wrapper would be needed.
Just need to implement this ability: https://www.roc-lang.org/builtins/Hash#Hash
And you should be able to just implemented by calling Hash.hash
on the inner type wrapped by the opaque.
yeah so to auto-derive, you can just say implements [Eq, Hash]
Would be great to have an example of an Opaque type with these abilities in https://github.com/roc-lang/examples if anyone feels like writing that up
Richard Feldman said:
yeah so to auto-derive, you can just say
implements [Eq, Hash]
oh....missed that we added that. awesome.
Richard Feldman said:
yeah so to auto-derive, you can just say
implements [Eq, Hash]
Yes! Thank you!
Bryce Miller has marked this topic as resolved.
Issue #106 created for this
Last updated: Jul 06 2025 at 12:14 UTC