我有两个自然数列表对,想检查它们的相等性。
Fixpoint beq_natlist (l1 l2 : list*list) : bool :=
match l1, l2 with
| (nil , nil) => true
| (h :: nil, nil) => false
| ( nil , h :: nil) => false
| h1 :: t1, h2 :: t2 => if beq_nat h1 h2 then beq_natlist t1 t2 else false
end.
答案 0 :(得分:1)
首先,list nat
的相等性如下所示。请注意,多重匹配模式a, b
和对表示法(a, b)
是完全不同的两件事。前者匹配两个词,而后者匹配一个词对。
Fixpoint beq_natlist (l1 l2 : list nat) : bool :=
match l1, l2 with
| nil, nil => true
| h :: nil, nil => false
| nil, h :: nil => false
| h1 :: t1, h2 :: t2 => if beq_nat h1 h2 then beq_natlist t1 t2 else false
end.
然后,您可以使用beq_natlist
来建立list nat * list nat
的等式:
Fixpoint beq_natlist_pair (p1 p2 : list nat * list nat) : bool :=
match p1, p2 with
| (l1, l2), (l3, l4) => beq_natlist l1 l3 && beq_natlist l2 l4
end.