在dhall中对Haskell类型Map ([Text], [Text]) Text进行编码的最佳方法是什么?
尝试。,我们似乎不能使用toMap来这样做:
-- ./config.dhall
toMap { foo = "apple", bar = "banana"} : List { mapKey : Text, mapValue : Text }x <- input auto "./config.dhall" :: IO Map Text Text因为我们需要映射的域为([Text], [Text])类型。
发布于 2020-05-12 15:32:53
Dhall中的Map只是mapKey/mapValue对的List:
$ dhall <<< 'https://prelude.dhall-lang.org/v16.0.0/Map/Type'
λ(k : Type) → λ(v : Type) → List { mapKey : k, mapValue : v }..。Haskell实现将类似于(a, b)的二元组编码为{ _1 : a, _2 : b },因此对应于Haskell类型的Dhall类型是:
List { mapKey : { _1 : List Text, _2 : List Text }, mapValue : Text }您不能使用toMap来构建该类型的值,这是正确的,因为toMap只支持带有Text-valued键的Map。但是,由于Map只是特定类型List的同义词,所以可以直接写出List (就像在Haskell中使用Data.Map.fromList一样),如下所示:
let example
: List { mapKey : { _1 : List Text, _2 : List Text }, mapValue : Text }
= [ { mapKey = { _1 = [ "a", "b" ], _2 = [ "c", "d" ] }, mapValue = "e" }
, { mapKey = { _1 = [ "f" ], _2 = [ "g", "h", "i" ] }, mapValue = "j" }
]
in examplehttps://stackoverflow.com/questions/61739508
复制相似问题