来自Record类型的模式匹配

时间:2013-05-28 03:41:03

标签: coq

我有一个记录类型,例如:

 Record matrixInt : Type := mkMatrixInt {
    const : vector nat dim;
    args : vector (matrix dim dim) argCnt
  }.

我有一个模式匹配,它返回matrixInt的类型,我称之为p,例如:(其中function_name p将返回matrixInt类型。我想要将p分成2个字段:constargs,例如我想要的草稿代码:

Definition my_function cons arg p :=
match function_name p with 
 | const => const + cons
 | args => args + arg
end.

你能帮我写一下p的模式匹配,它会返回2个字段const; args吗? 非常感谢你!

2 个答案:

答案 0 :(得分:1)

记录(双关语):

Record test :=
{ T : Type
; t : T
}.

(* The fields names are indeed accessor functions *)
Definition foo (x : test) : T x := t x.

(* you can destruct a record by matching against its data constructor *)
Definition bar (x : test) : T x :=
  match x as _x return T _x with
  | Build_test T' t' => t'
  end.

(* You can even destruct a record with a let *)
Definition baz (x : test) : T x :=
  let (T', t') as _x return T _x := x in t'.

答案 1 :(得分:0)

谢谢,我找到了答案:(const p)(args p)