I'm trying to add an ability for dict in Decode.roc and the relevant function in Json.roc. When doing roc check on Json.roc I'm getting the error?
The DecoderFormatting ability does not have a member dict
120│ dict: decodeDict,
^^^^
Only implementations for members an ability has can be specified in
this location.
Can you share the larger chunk of surrounding code?
Sure, here is relevant part of Json.roc with the issue. You can see I added the member dict at the bottom
Json := {} has [
EncoderFormatting {
u8: encodeU8,
u16: encodeU16,
u32: encodeU32,
u64: encodeU64,
u128: encodeU128,
i8: encodeI8,
i16: encodeI16,
i32: encodeI32,
i64: encodeI64,
i128: encodeI128,
f32: encodeF32,
f64: encodeF64,
dec: encodeDec,
bool: encodeBool,
string: encodeString,
list: encodeList,
record: encodeRecord,
tag: encodeTag,
},
DecoderFormatting {
u8: decodeU8,
u16: decodeU16,
u32: decodeU32,
u64: decodeU64,
u128: decodeU128,
i8: decodeI8,
i16: decodeI16,
i32: decodeI32,
i64: decodeI64,
i128: decodeI128,
f32: decodeF32,
f64: decodeF64,
dec: decodeDec,
bool: decodeBool,
string: decodeString,
list: decodeList,
record: decodeRecord,
dict: decodeDict,
},
]
and I added to Decode.roc and also exposed it
DecoderFormatting has
u8 : Decoder U8 fmt | fmt has DecoderFormatting
u16 : Decoder U16 fmt | fmt has DecoderFormatting
u32 : Decoder U32 fmt | fmt has DecoderFormatting
u64 : Decoder U64 fmt | fmt has DecoderFormatting
u128 : Decoder U128 fmt | fmt has DecoderFormatting
i8 : Decoder I8 fmt | fmt has DecoderFormatting
i16 : Decoder I16 fmt | fmt has DecoderFormatting
i32 : Decoder I32 fmt | fmt has DecoderFormatting
i64 : Decoder I64 fmt | fmt has DecoderFormatting
i128 : Decoder I128 fmt | fmt has DecoderFormatting
f32 : Decoder F32 fmt | fmt has DecoderFormatting
f64 : Decoder F64 fmt | fmt has DecoderFormatting
dec : Decoder Dec fmt | fmt has DecoderFormatting
bool : Decoder Bool fmt | fmt has DecoderFormatting
string : Decoder Str fmt | fmt has DecoderFormatting
list : Decoder elem fmt -> Decoder (List elem) fmt | fmt has DecoderFormatting
record : state, (state, Str -> [Keep (Decoder state fmt), Skip]), (state -> Result val DecodeError) -> Decoder val fmt | fmt has DecoderFormatting
dict : Decoder elem fmt -> Decoder (Dict Str elem) fmt | fmt has DecoderFormatting
Ah, yeah, you can't add a new value there.
DecodeFormatting is defined here: https://github.com/roc-lang/roc/blob/a80b25d0447666719d26eb5717c62c7fe6b9a54f/crates/compiler/builtins/roc/Decode.roc#L62
All other types have to be defined in terms of those primatives.
I believe you would need to define the Decoding ability for Dict or some Dict wrapper type (though should get added to the standard library Dict: https://github.com/roc-lang/roc/blob/a80b25d0447666719d26eb5717c62c7fe6b9a54f/crates/compiler/builtins/roc/Decode.roc#L59
Decoding uses those primitives to decode a list of bytes into another type. in this case, Dict.
So you probably want to use create a definition that first decodes a List (k, v) Then it creates a dictionary from the list.
Or something of that nature.
Though I guess json has a native dict type, so maybe we need native decoding for it, I am not fully sure how these things compose.
Turns out my question was with the fact I needed to run cargo build in order to get the new DecoderFormatting member dict
@Seth Workman I'm interested to know how you went here? Any success adding Dicts for Json decoding?
Not far enough, just got a generic method compiling but nothing actually working. I don't have enough knowledge of how its all linked together yet
Last updated: Nov 09 2025 at 12:14 UTC