簡體   English   中英

如何在Coq中明確提供隱式參數?

[英]How do I provide implicit arguments explicitly in Coq?

假設我有一個定義f : x -> y -> z ,其中x可以很容易地推斷出來。 因此,我選擇使用Arguments使x成為隱式Arguments

請考慮以下示例:

Definition id : forall (S : Set), S -> S :=
fun S s => s.

Arguments id {_} s.

Check (id 1).

很明顯, S = nat可以是Coq推斷出來的,Coq回復:

id 1
     : nat

但是,在稍后的時間,我想隱含的參數是明確的,比如,為了便於閱讀。

換句話說,我想要像:

Definition foo :=
 id {nat} 1. (* We want to make it clear that the 2nd argument is nat*)

這有可能嗎? 如果是這樣,那么適當的語法是什么?

您可以在@前面添加名稱以刪除所有含義並明確提供它們:

Check @id nat 1.

您還可以使用(a:=v)按名稱傳遞隱式參數。 這既可以澄清傳遞的參數,也可以傳遞一些含義而不傳遞_為其他參數:

Check id (S:=nat) 1.

Definition third {A B C:Type} (a:A) (b:B) (c:C) := c.
Check third (B:=nat) (A:=unit) tt 1 2.

一種可能的方法是在定義之前加上@ 例如:

Definition id : forall (S : Set), S -> S :=
fun S s => s.

Arguments id {_} s.

Check @id nat 1.

結果如下:

id 1
     : nat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM