dhall - Dynamic records key type
问题描述
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
解决方案
您的问题启发了添加此功能,该功能将在下一个版本(版本 1.25.0)中提供。看:
https://github.com/dhall-lang/dhall-haskell/pull/1094
这也将在另一个方向上起作用,这意味着{json,yaml}-to-dhall
如果架构要求,它将能够将记录键解码为联合:
$ 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 } ]
推荐阅读
- mongodb - MongoDB动态子字段名称
- python - Docker:无法从 dockerfile 安装 Python 库,尽管可以从容器的 shell 中手动安装它们
- python - 向 pandas DataFrame wint 索引名称和列名称添加单个值
- java - 我无法在 recyclerview 中使用 sqlite 显示新添加的数据
- java - Java Android ImageView-图像旋转仅第一次起作用
- vb.net - 后台工作者可以共享功能吗
- python - ConnectionRefusedError: Python 程序突然开始给出这个错误
- python - python - 如何在python中将日期时间格式Year-Quarter转换为Quarter-Year?
- c# - 是否可以在 c# 中编写文件大小不能被 4 整除的二进制文件?
- amazon-web-services - AWS Cloud 9 无需安装即可使用 CS50 IDE