在预计列表的构造函数的同时,找到了一个归纳类型bool的构造函数
我有以下问题:定义fonction值:list bool - >返回由布尔值列表表示的值(二进制号为十进制数字)的NAT。例如,值[false; true; false; true] = 10。 我写了这篇文章:
Fixpoint value (l: list bool) := match l with
|true=> 1
|false=> 0
|x::r => (value [x])+2*(value r)
end.
但是我得到了这个错误:“找到了归纳类型bool的构造函数 而列表的构造函数 期望
。 但这仍然行不通...我该怎么办?
I have the following question : Define the fonction value : list bool -> nat that return the value represented by a list of booleans(binary number to decimal number). For example, value [false;true;false;true] = 10.
I wrote this:
Fixpoint value (l: list bool) := match l with
|true=> 1
|false=> 0
|x::r => (value [x])+2*(value r)
end.
but I get this error : "Found a constructor of inductive type bool
while a constructor of list
is expected."
I have tried to put false and true as bool list : [false] [true]
but it still doesn't work... What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,Coq正确地抱怨您应该使用构造函数进行列表,
true
和false
是布尔值,而不是布尔值列表。您是对的,应该使用[true]
和[false]
。然后,COQ仍然应该抱怨您没有在空列表上指定您的功能,因此您需要为此添加一个案例:
这次Coq仍然会抱怨,但出于另一个原因:它不知道<<<代码> [x] 小于
x :: r
。因为不是句法。要修复它,我建议简单地处理两种情况:
true
和false
。无论如何,这会产生更简单的东西:Indeed, Coq rightfully complains that you should use a constructor for list, and
true
andfalse
are booleans, not lists of booleans. You are right that[true]
and[false]
should be used.Then after this, Coq should still complain that you did not specify your function on the empty list, so you need to add a case for it like so:
This time Coq will still complain but for another reason: it doesn't know that
[x]
is smaller thanx :: r
. Because it isn't the case syntactically.To fix it, I suggest to simply deal with the two cases:
true
andfalse
. This yields something simpler in any case: