0

Map ([Text], [Text]) Text在 dhall中编码 Haskell 类型的最佳方法是什么?

试图。看来我们不能toMap用来这样做:

-- ./config.dhall

toMap { foo = "apple", bar = "banana"} : List { mapKey : Text, mapValue : Text }
x <- input auto "./config.dhall" :: IO Map Text Text

因为我们需要地图的域是 type ([Text], [Text])

4

1 回答 1

1

Dhall 中的AMap只是/对中的一个:ListmapKeymapValue

$ dhall <<< 'https://prelude.dhall-lang.org/v16.0.0/Map/Type'
λ(k : Type) → λ(v : Type) → List { mapKey : k, mapValue : v }

...并且 Haskell 实现将 2 元组编码为(a, b)as { _1 : a, _2 : b },因此与您的 Haskell 类型对应的 Dhall 类型为:

List { mapKey : { _1 : List Text, _2 : List Text }, mapValue : Text }

您是正确的,您不能使用它toMap来构建该类型的值,因为toMap仅支持Map带有Text-valued 键的 s 。但是,由于 aMap只是特定类型的同义词,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  example
于 2020-05-12T15:32:53.993 回答