Coq: Ltac definitions over variable argument lists?

前端 未结 1 1456
日久生厌
日久生厌 2021-01-18 02:26

While trying to create an Ltac definition that loops over a variable-length argument list, I encountered the following unexpected behavior on Coq 8.4pl2. Can anyone explain

相关标签:
1条回答
  • 2021-01-18 02:36

    Let's expand the last invocation of ltac_loop to see what's happening:

    ltac_loop 1 1 0
    -> (fun Y => idtac "hello"; ltac_loop Y) 1 0
    -> (idtac "hello"; ltac_loop 1) 0
    

    There you can see the problem: you are trying to apply something that is not a function to an argument, which results in the error you saw. The solution is to rewrite the tactic in continuation-passing style:

    Ltac ltac_loop_aux k X :=
      match X with
      | 0 => k
      | _ => (fun Y => ltac_loop_aux ltac:(idtac "hello"; k) Y)
      end.
    
    Ltac ltac_loop X := ltac_loop_aux ltac:(idtac "done") X.
    
    0 讨论(0)
提交回复
热议问题