我有一个记录类型,例如:
Record matrixInt : Type := mkMatrixInt {
const : vector nat dim;
args : vector (matrix dim dim) argCnt
}.
我有一个模式匹配,它返回matrixInt
的类型,我称之为p
,例如:(其中function_name p
将返回matrixInt
类型。我想要将p
分成2个字段:const
和args
,例如我想要的草稿代码:
Definition my_function cons arg p :=
match function_name p with
| const => const + cons
| args => args + arg
end.
你能帮我写一下p
的模式匹配,它会返回2个字段const; args
吗?
非常感谢你!
答案 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)