I'm trying to generate some YAML containing a map with dynamic keys, as described here. This works if I use Text keys, but not when the keys have any other type. I'd like to use a union type for the keys if possible.
I've tried using different types for mapKey, including a union type and Natural, but with no success. I can work around the problem by converting all mapKey values to Text, but this isn't ideal.
Here's a minimal example of what I'm trying to do:
let Union = <A | B>
in
[{mapKey = Union.A, mapValue = "foo"}]
I'd expect it to generate YAML to be:
A: foo
but instead, the generated YAML looks like this:
- mapKey: A
mapValue: foo
Your question inspired adding this feature, which will be available in the next release (Version 1.25.0). See:
https://github.com/dhall-lang/dhall-haskell/pull/1094
This will also work in the other direction, meaning that {json,yaml}-to-dhall will be able to decode record keys into a union if requested to by the schema:
$ json-to-dhall 'List { mapKey : < A | B >, mapValue : Natural }' <<< '{"A": 1, "B": 2}'
[ { mapKey = < A | B >.A, mapValue = 1 }, { mapKey = < A | B >.B, mapValue = 2 } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With