A simple Ltac2 tactic to debug broken "refine" statements #2265
patrick-nicodemus
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
There is also |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I often run into errors when using
refine
but sometimes the error messages are a little bit overwhelming. One of the uses I see for writing custom tactics is to basically just reimplement tactics which already exist but inserting handwritten error messages to indicate the point of failure, and make the problem easier to fix.I decided to implement my own fairly naive
refine_debug
tactic as follows:refine_debug(s)
computes the type of the terms
and tries to unify it with the goal typeg
by callingunify_debug
.unify_debug t g
works as follows:t
andg
are both applicationsf x1 x2... xn
, then first try to unify the heads of both applications, then check that the argument lists are the same length, and recursively callunify_debug
on each parallel pair of arguments. Otherwise just try tounify
them using the standard tactic.Ideally, if the type of your term has broadly the same shape as the shape of the goal, calling this function will tend to recurse through the subterms, unifying as they go, and when it fails it will fail at the smallest pair of parallel subterms in the structure which failed to unify, so you'll have a more readable error message. In addition, because
unify
succeeded at all previous terms, you'll have a clear picture of which unification variables were already solved, whereas when you just try to unify both terms all at once, it reports "t failed to unify with g" wheret
contains all the holes that were present originally (since unification failed, it is regarded as solving none of these holes, when in reality it probably solved many of them.)Right now I'm just copy-pasting this snippet into the library temporarily when I am having trouble getting
refine
to work. I highly recommend upgrading to Rocq 9.0 before trying this because of the typeclass hintdb bug in Coq 8.20 and below.Beta Was this translation helpful? Give feedback.
All reactions