I think I'm doing something wrong while constructing an opaque type.
The type definition:
JsonValue := [
JsonNull,
JsonBool Bool,
JsonNum F64,
JsonStr Str,
JsonArray (List JsonValue),
JsonDict (List [Pair Str JsonValue]),
]
I have a JsonArray (List JsonValue)
and I want to wrap it so it becomes a JsonValue
itself.
── TYPE MISMATCH ──────────────────────────────── examples/json/ParserJson.roc ─
The 2nd argument to map is not what I expect:
66│ |> map (\res -> @JsonValue res)
^^^^^^^^^^^^^^^^^^^^^^
This argument is an anonymous function of type:
[JsonArray (List a), JsonBool Bool, JsonDict (List [Pair Str a]),
JsonNull, JsonNum F64, JsonStr Str] as a -> JsonValue
But map needs the 2nd argument to be:
[JsonArray (List JsonValue)] -> JsonValue
────────────────────────────────────────────────────────────────────────────────
what does the rest of your program look like?
In particular what is map
and what are you feeding into it before the pipeline operator?
What map is: A function with the signature map : Parser input a, (a -> b) -> Parser input b
(source: https://github.com/rtfeldman/roc/blob/f4c0925b21afcb46fd6bd0315b19ee97d942a8f8/examples/json/ParserCore.roc#L185-L190 )
What I am feeding (types given at every step as I tried very hard to find out why the compiler was unhappy) https://github.com/rtfeldman/roc/blob/f4c0925b21afcb46fd6bd0315b19ee97d942a8f8/examples/json/ParserJson.roc#L52-L66
okay I have a patch for this. I'll send it to you in a couple hours.
Thanks a lot for your hard work! :bow:
Last updated: Jul 06 2025 at 12:14 UTC