簡體   English   中英

是否可以將上下文模式轉換為 Gallina 函數?

[英]Is it possible to turn a context pattern into a Gallina function?

在 Ltac 中,上下文模式可用於構建Ltac 級函數,該函數接受一個 Gallina 項並通過填充一個洞來構造一個 Gallina 項。 我想具體化這個功能並在 Gallina 級別使用它,而不是 Ltac。

例如,以下代碼使用元變量而不是上下文模式工作。

Variables 
  (A : Set)
  (P : A -> Prop)
  (a : A)
  (H : forall Q: A -> Prop, Q a).


Goal (P a).
match goal with
  | |- ?P a => exact (H P)
end.
Qed.

但是以下代碼不起作用,因為在填充模式之前我無法將變量x帶入范圍:

Goal (P a).
match goal with
  | |- context C[a] => let y := context C[x] in exact (H (fun x => y))
end.
(* The reference x was not found in the current
environment. *)

以下也不起作用,因為我無法在 Gallina 中使用 Ltac:

Goal (P a).
match goal with
  | |- context C[a] => let y := exact (H (fun x => context C[x]))
end.
(* Syntax error... *)

但以下代碼顯示我的上下文模式的工作方式與我認為的一樣:

Goal (P a).
match goal with
  | |- context C[a] => let y := context C[a] in idtac y
end.
(* (P a) *)

雖然這個例子很簡單,因為目標是單個應用程序,但一般來說,我想使用上下文模式來匹配更復雜的目標,然后使用這些模式來構建 Gallina 函數。 這能做到嗎?

使用ltac:(...)

match goal with
  | |- context C[a] => exact (H (fun x => ltac:(let y := context C[x] in exact y)))
end.

ltac:(...)可以替換任何 Gallina 術語。 該漏洞的預期類型成為包含的策略表達式的目標,執行該表達式以生成新的 Gallina 項來填充該漏洞。

暫無
暫無

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

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