Inductive list (A: Type) : Type := | nil : list A | cons : A -> list A -> list A. (* Check (cons nat 3 (nil nat)). *) Implicit Arguments nil [A]. Implicit Arguments cons [A]. (* Check (cons 3 nil). *) Fixpoint append {A : Type} (xs ys: list A) : list A := match xs with | nil => ys | cons x xs => cons x (append xs ys) end. Infix "++" := append (at level 60). Fixpoint length {A : Type} (xs : list A) : nat := match xs with | nil => O | cons x xs => S (length xs) end. Theorem append_assoc : forall (A: Type) (xs ys zs : list A), (xs ++ ys) ++ zs = xs ++ (ys ++ zs). Proof. (* あなたの証明を書いてね *) Qed. Theorem append_length : forall (A: Type) (xs ys: list A), length (xs ++ ys) = length xs + length ys. Proof. (* あなたの証明を書いてね *) Qed.
これで append 関数の 結合則が証明できた。 似たようなやり方で関数型プログラムの証明を書いて行くことができる。Coqすばらしす。