Coq中的依赖类型列表连接

Coq中的依赖类型列表连接,coq,Coq,我有一个带有对象和箭头的图,从中我定义了箭头路径的概念。我想定义这些路径的连接。下面的代码是我天真的尝试。但是当match子句中的p'为emptyPath时,我得到了一个错误:“术语“p”的类型为“path A B”,而预期它的类型为 “路径A C.”概念上应该没有问题,因为在这种情况下B等于C。我怎样才能让它工作 Parameter Object : Set. Parameter Arrow : Object -> Object -> Set. Inductive path :

我有一个带有对象和箭头的图,从中我定义了箭头路径的概念。我想定义这些路径的连接。下面的代码是我天真的尝试。但是当
match
子句中的
p'
emptyPath
时,我得到了一个错误:“术语“p”的类型为“path A B”,而预期它的类型为 “路径A C.”概念上应该没有问题,因为在这种情况下
B
等于
C
。我怎样才能让它工作

Parameter Object : Set.
Parameter Arrow : Object -> Object -> Set.

Inductive path : Object -> Object -> Set :=
  emptyPath : forall X, path X X
| cons : forall {A B C} (p : path A B) (f : Arrow B C), path A C.

Fixpoint concat {A B C : Object} (p : path A B) (p' : path B C) :  path A C :=
  match p' return path A C with
    | emptyPath _ => p
    | cons _ _ _ p0 f => cons (concat p p0) f
  end. 
无论何时,只要定义中有“可变指数”,就需要应用所谓的“护航模式”来让定义起作用。基本思想是重新抽象一些参数,以便依赖模式匹配可以“更改”它们的类型

Parameter Object : Set.
Parameter Arrow : Object -> Object -> Set.

Inductive path : Object -> Object -> Set :=
  emptyPath : forall X, path X X
| cons : forall {A B C} (p : path A B) (f : Arrow B C), path A C.

Fixpoint concat {A B C : Object} (p : path A B) (p' : path B C) :  path A C :=
  match p' in path B C return path A B -> path A C with
    | emptyPath _ => fun p => p
    | cons _ _ _ p0 f => fun p => cons (concat p p0) f
  end p.
你可以在Adam Chlipala的书中了解更多关于护航模式的信息

(* You could use Program *)

Parameter Object : Set.
Parameter Arrow : Object -> Object -> Set.

Inductive path : Object -> Object -> Set :=
  emptyPath : forall X, path X X
| full : forall {A B C} (p : path A B) (f : Arrow B C), path A C.

Require Import Coq.Program.Program.

Program Fixpoint concat {A B C : Object} (p : path A B) (p' : path B C) :  path A C :=
  match p' with
    | emptyPath _ => p
    | full _ _ _ p0 f => full (concat p p0) f
  end. 

(* Unfortunately, I don't think Program produces an easy way to unfold
or simpl the definitions it produces, so programs about them are
difficult. *)

(* You could also switch to an unyped representation. I find this
method much easier to reason about. *)

Definition sArrow := prod Object Object.

Definition spath := list sArrow.

Fixpoint bound (xs:spath) a b :=
  match xs with
    | nil => a = b
    | cons y ys =>
      a = fst y /\
      bound ys (snd y) b
  end.

Lemma concatBound : forall xs a b c ys (top:bound xs a b), bound ys b c -> bound (xs ++ ys)%list a c.
induction xs; intros.
{
  unfold app; unfold bound in *; subst; assumption.
}
{
  simpl in *.
  destruct top; split; subst; auto.
  eapply IHxs; solve [eauto].
}
Qed.