我正在學習Coq並且作爲練習我想定義一個類型FnArity (N:nat)
來編碼所有函數的N
參數。那就是:類型包含Coq中的N個元素的所有功能
Check FnArity 3 : (forall A B C : Set, A -> B -> C).
應該工作,但
Check FnArity 2 : (forall A B C D : Set, A -> B -> C -> D).
不應該工作。
這是爲了教學目的,所以任何相關的資源是值得歡迎的。
編輯:從到目前爲止的答案我意識到我可能接近這個錯了,所以這裏是我想證明的命題: 創作ň組成運營商就相當於對構成f
和g
組成算哪裏g
預計ñ參數。在Haskell上下的術語:
(.).(.) ... N times ... (.).(.) f g = \a1, .. aN -> f (g (a1, .. , aN))
EDIT2:在COQ方面:
Definition compose { A B C : Type } (F : C -> B) (G : A -> C) : A -> B :=
fun x => F (G (x)).
Definition compose2 {A1 A2 B C : Type} (F : C -> B) (G : A1 -> A2 -> C)
: A1 -> A2 -> B := fun x y => F (G x y).
Definition compose3 {A1 A2 A3 B C : Type} (F : C -> B) (G : A1 -> A2 -> A3 -> C)
: A1 -> A2 -> A3 -> B := fun x y z => F (G x y z).
(* The simplest case *)
Theorem dual_compose : forall {A B C D : Type} (f: D -> C) (g : A -> B -> D) ,
(compose compose compose) f g = compose2 f g.
Proof. reflexivity. Qed.
Theorem triple_compose : forall {A1 A2 A3 B C : Type} (f: C -> B) (g : A1 -> A2 -> A3 -> C) ,
(compose (compose (compose) compose) compose) f g =
compose3 f g.
我想是定義廣義定理composeN
。
你確實似乎回答我的問題,但我不能讓派生類型爲我的問題工作。你能檢查我的編輯並修改你的回答評論嗎? – fakedrake
@fakedrake在這種情況下,你可能只需要'FnArityAux1'類型。我會看看我能不能拿出一些東西。 –
另外''符號是什麼意思。我認爲它是某種中綴存在量詞,但我找不到有關它的文檔? – fakedrake