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?
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: