定义一个';头部';对于Coq中的共导类型流(无模式匹配)

定义一个';头部';对于Coq中的共导类型流(无模式匹配),coq,coinduction,Coq,Coinduction,1) 我相信不需要模式匹配就可以使用归纳类型。(仅使用_rec、_rect、_ind)。这是不透明的、复杂的,但也是可能的。 2) 是否可以将共导类型与非共导模式匹配一起使用 存在一个从共导型到共导型构造函数域并集的函数。 Coq是否显式生成它? 如果是,如何重写“hd” Section stream. Variable A : Type. CoInductive stream : Type := | Cons : A -> stream -> stream. End

1) 我相信不需要模式匹配就可以使用归纳类型。(仅使用_rec、_rect、_ind)。这是不透明的、复杂的,但也是可能的。 2) 是否可以将共导类型与非共导模式匹配一起使用

存在一个从共导型到共导型构造函数域并集的函数。 Coq是否显式生成它? 如果是,如何重写“hd”

Section stream.
  Variable A : Type.

  CoInductive stream : Type :=
  | Cons : A -> stream -> stream.
End stream.

Definition hd A (s : stream A) : A :=
  match s with
    | Cons x _ => x
  end.

虽然可以使用归纳类型而不直接诉诸模式匹配,但这只是表面上的事实:Coq生成的
\u rec
\rect
\u ind
组合都是根据
匹配定义的。例如:

Print nat_rect.

nat_rect = 
fun (P : nat -> Type) (f : P 0) (f0 : forall n : nat, P n -> P (S n)) =>
fix F (n : nat) : P n :=
  match n as n0 return (P n0) with
  | 0 => f
  | S n0 => f0 n0 (F n0)
  end
     : forall P : nat -> Type,
       P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n
此外,在许多情况下,用消除器替换模式匹配将导致具有不同计算行为的项。考虑下面的函数,它将<代码> NAT < /> >两个:

Fixpoint div2 (n : nat) :=
  match n with
  | 0 | 1 => 0
  | S (S n') => S (div2 n')
  end.
可以使用
nat_rec
重写此函数,但是对
n-2
的递归调用使它有点复杂(试试!)

现在,回到您的主要问题,Coq不会自动为共导类型生成类似的消除原则。该库有助于推导出更有用的原理,用于对共推数据进行推理。但据我所知,编写普通函数没有类似的功能

值得指出的是,您提出的方法不同于Coq对归纳数据类型所做的,因为
nat\u rect
和friends允许通过归纳编写递归函数和证明。提供这些组合符的原因之一是它们被
归纳法
策略使用。某种类型的
nat->unit+nat
,或多或少符合您的建议,是不够的