答案取决于关联列表中存储的值的类型。在最一般的情况下,您可以在 的Blah
类型上对类型进行参数化mapValue
,如下所示:
let Blah =
λ(a : Type)
→ < First :
{ name : Text, params : List { mapKey : Text, mapValue : a } }
| Second :
{ name : Text }
>
in (Blah Natural).First
{ name = "Alex", params = [ { mapKey = "a", mapValue = 1 } ] }
mapValue
如果您提前知道所需的类型,则可以对其进行硬编码,而不是创建Blah
一个类型的函数。或者,如果您打算多次使用Blah
同一mapValue
类型,您可以执行以下操作:
let Blah =
λ(a : Type)
→ < First :
{ name : Text, params : List { mapKey : Text, mapValue : a } }
| Second :
{ name : Text }
>
let Foo = Blah Natural
in [ Foo.First { name = "Alex", params = [ { mapKey = "a", mapValue = 1 } ] }
, Foo.Second { name = "John" }
]