问题描述
我正在使用 Dhall 1.39.0 并收到此错误:
Error: Expression doesn't match annotation
- Text
+ { … : … } (a record type)
[snip]
You or the interpreter annotated this expression:
[ file contents ]
... with this type or kind:
↳ Text
... but the inferred type or kind of the expression is actually:
↳ { Sentences :
List
{ Name : Text,Object : Text,Statement : Bool,Subject : Text,Verb : Text
},Version : Text
}
这是从 cat show-and-tell.dhall | ~/external-programs/bin/dhall --explain text
产生的。
请注意,我可以将相关的 dhall 文件加载到 dhall-golang 库中并使其正确呈现。所以我有点困惑。
let Sentence : Type =
{
Name : Text,Verb : Text,Statement : Bool
}
let information : Type = {
Version : Text,Sentences : List Sentence
}
let all = ".+"
let answer : information = {
Version = "v1",Sentences =
[ { Name = "s1",Subject = "bobross",Verb = "${all}",Object = "${all}",Statement = True
},{ Name = "s2",Subject = "Everyone",Statement = False
},{ Name = "s3",Subject = "picasso",Verb = "questions",Statement = True
}
]
}
in answer
解决方法
dhall text
用于呈现 Text
类型的 Dhall 表达式的值(有点像,例如 -r
的 jq
选项):
$ echo '"Foo"' | dhall text
Foo
相比
$ echo '"Foo"' | dhall
"Foo"
你的表达式类型为 Information
;您只需要 dhall
本身。
$ cat show-and-tell.dhall | dhall
{ Sentences =
[ { Name = "s1",Object = ".+",Statement = True,Subject = "bobross",Verb = ".+"
},{ Name = "s2",Statement = False,Subject = "Everyone",{ Name = "s3",Subject = "picasso",Verb = "questions"
}
],Version = "v1"
}