Require Import Arith.
(* Create a module type for some type A with some general properties. *)
Module Type ModA.
Parameter A: Type.
Axiom a_dec: forall a b:A, {a=b}+{a<>b}.
End ModA.
(* Define the function that uses the A type in another module
that imports a ModA type module *)
Module FMod (AM: (ModA)).
Import AM.
Definition f (a1 a2:A) := if a_dec a1 a2 then 1 else 2.
End FMod.
(* Here's how to use f in another module *)
Module FTheory (AM:ModA).
Module M := FMod AM.
Import M.
Import AM.
Theorem f_theorem: forall a, f a a = 1.
intros. compute. destruct (a_dec _ _).
auto. congruence.
Qed.
End FTheory.
(* Eventually, instatiate the type A in some way,
using subtyping '<:'. *)
Module ModANat <: ModA.
Definition A := nat.
Theorem a_dec: forall a b:A, {a=b}+{a<>b}.
apply eq_nat_dec.
Qed.
End ModANat.
(* Here we use f for your particular type A *)
Module FModNat := FMod ModANat.
Compute (FModNat.f 3 4).
Recursive Extraction FModNat.f.
Goal FModNat.f 3 3 = 1.
Module M := FTheory ModANat.
apply M.f_theorem.
Qed.
你看過[使用模塊指南](https://coq.inria.fr/cocorico/ModuleSystemTutorial)嗎? – larsr
謝謝,現在看看它。看起來'Module Type'只能包含'Axiom'和'Parameter'。因爲'f'會有一個body(我已經定義了它''Definition'),所以我不能把它放到'Module Type'中。自動櫃員機我不知道如何滿足我的問題1-2點(甚至沒有認真考慮過3) – jaam