标签: convoy-pattern

在Coq中实现向量加法

在一些依赖类型的语言(例如Idris)中实现向量添加是相当简单的.根据维基百科上示例:

import Data.Vect

%default total

pairAdd : Num a => Vect n a -> Vect n a -> Vect n a
pairAdd Nil       Nil       = Nil
pairAdd (x :: xs) (y :: ys) = x + y :: pairAdd xs ys
Run Code Online (Sandbox Code Playgroud)

(注意Idris的整体检查器如何自动推断添加Nil和非Nil向量是逻辑上不可能的.)

我正在尝试使用自定义向量实现在Coq中实现等效功能,尽管与官方Coq库中提供的非常相似:

Set Implicit Arguments.

Inductive vector (X : Type) : nat -> Type :=
  | vnul : vector X 0 
  | vcons {n : nat} (h : X) …
Run Code Online (Sandbox Code Playgroud)

vector coq idris convoy-pattern

4
推荐指数
1
解决办法
473
查看次数

使用定理信息的模式匹配

我有以下问题,请查看代码。

  (* Suppose we have type A *)
  Variable A: Type.

  (* Also we have a function that returns the type (option A) *)
  Definition f_opt x: option A := ...

  (* Then, I can prove that this function always returns something: *)
  Theorem always_some: forall x, exists y, f_opt x = Some y.
  Admitted.

  (* Or, equivalently: *)
  Theorem always_not_none: forall x, f_opt x <> None.
  Admitted.
Run Code Online (Sandbox Code Playgroud)

现在我想得到一个f_opt总是返回 type 值的版本A。像这样的东西:

  Definition f x: A := …
Run Code Online (Sandbox Code Playgroud)

pattern-matching coq dependent-type convoy-pattern

2
推荐指数
2
解决办法
464
查看次数