我有一个异构列表,如 CPDT 中所述:
Section hlist.
Variable A : Type.
Variable B : A -> Type.
Inductive hlist : list A -> Type :=
| HNil : hlist nil
| HCons : forall (x : A) (ls : list A), B x -> hlist ls -> hlist (x :: ls)
.
End hlist.
并尝试在Ensemble
s 列表和元素列表之间定义“逐点成员资格”谓词:
Definition hlist_in_ensemble_hlist {A : Type}{B : A -> Type}(types : list A)
(sets : hlist A (fun a => Ensemble (B a)) types) (elems : hlist A B types) : Prop :=
match sets with
| HNil _ _ => True
| HCons _ _ a1 a1s b1 b1s =>
match elems with
| HNil _ _ => False
| HCons _ _ a2 a2s b2 b2s =>
Ensembles.In (B a1) b1 b2 (* /\ recursion (TODO) *)
end
end.
然而,Coq 抱怨这Ensembles.In (B a1) b1 b2
部分:
The term "b2" has type "B a2" while it is expected to have type "B a1"
直观地说,a1
和a2
是相同的,因为它们是同一个types
列表的头部。我如何将它传达给 Coq?我尝试匹配elems
并将cons x xs
违规行更改为Ensembles.In (B x) b1 b2
,但这会导致类似的错误。我还阅读了有关 Convoy 模式的信息,但不确定如何在这种情况下应用它。