簡體   English   中英

模式匹配從目標模式匹配獲得的假設

[英]Pattern-matching a hypothesis obtained from a pattern-match on goal

考慮以下發展:

Definition done {T : Type} (x : T) := True.

Goal Test.
  pose 1 as n.
  assert (done n) by constructor.
  Fail ltac:(
    match goal with 
    | [ H : done _ |- _ ] => fail
    | [ H : _ |- _ ] =>
      match goal with
      | [ _: done H |- _ ] => idtac "H == n"
      | [ _: done n |- _ ] => idtac "H != n"; fail 2
      end
    end
  ).
Abort.

這將輸出H != n 我發現這非常令人驚訝,因為范圍內的唯一假設是n並且done n並且done n已經由頂級匹配的第一個分支調度。

我如何能匹配done n沒有明確提到n ,在第二場比賽的第一個分支?

我認為您對match的方式感到困惑。 匹配的第一個分支與每個假設都匹配,如果匹配始終失敗,則測試第二個分支,依此類推。 在您的示例中,第一個分支匹配假設H ,但是相應策略( fail )的執行失敗,因此嘗試了第二個分支也匹配假設H

實際上,外部match的第一個分支似乎可以滿足您的要求(即,在形式為done _的假設下進行匹配),所以我並沒有真正理解內部match

例如,

match goal with 
| [ H' : done _ |- _ ] => idtac H'
end.

打印H ,表明正確的假設是匹配的。

請注意,您不需要ltac:()表達式就可以在策略上使用Fail 例如, Fail fail. 作品。

暫無
暫無

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

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