agda-stdlib icon indicating copy to clipboard operation
agda-stdlib copied to clipboard

Add Case Bash Tactic

Open TOTBWF opened this issue 3 years ago • 11 comments

Patch Description

This PR adds the case-bash! tactic, which automates the process of performing exhaustive case splits followed by refl. This is best demonstrated with, well, a demo!

∧-comm : ∀ (x y : Bool) → x ∧ y ≡ y ∧ x
∧-comm = case-bash!

Details

The tactic begins by inspecting the current goal, which should be some pi type with a bunch of arguments that are non-implicit datatypes. It then walks down the pi type, hunting for visible datatype arguments. When we find one, grab all of it's constructor names, and push them onto a list that stores all possible constructor name combinations. This list is then used to generate a list of clauses whose bodies are all refl, which are finally used to construct a pattern lambda.

Limitations

This tactic is extremely brute force; it will case split on any datatype it finds, even if it doesn't show up in the goal whatsoever. Furthermore, it is not smart enough to insert absurd clauses, and thus will run straight into a type error when presented with indexed datatypes. Detecting when we need to insert absurd clauses is quite difficult though, and a tactic with limitations is better than no tactic at all.

TOTBWF avatar Dec 17 '22 06:12 TOTBWF

Thanks, this looks really nice! And I agree, better basic tactics than non at all!

I know the code is already extremely well documented but can we add some examples of using it in README.Tactics.CaseBash? That way they'll function as tests as well to avoid us accidentally breaking this in future :+1:

Also unfortunately the tests appear to be failing with a parse error. What version of Agda are you using?

MatthewDaggitt avatar Dec 19 '22 01:12 MatthewDaggitt

Also unfortunately the tests appear to be failing with a parse error. What version of Agda are you using?

Is this not due to the fact that I have retired return in favour of pure because return used to clash with case_return_of_?

Edit: pushed a fix, there was also a discrepancy in the type of extendContext so there's probably indeed an Agda version issue too.

Should we have a README with examples?

gallais avatar Dec 20 '22 13:12 gallais

Sorry! I've been a bit busy this week so I hadn't been keeping an eye on this. I did develop this against Agda HEAD and on experimental, which explains all of the silly mistakes 🙃. I'll add a README later tonight, and then we should be good to go!

TOTBWF avatar Dec 20 '22 22:12 TOTBWF

@TOTBWF any chance of that README appearing at some point so I can merge this in?

MatthewDaggitt avatar Jan 17 '23 07:01 MatthewDaggitt

I was working on the README and found a couple of gnarly scoping bugs, currently working on fixing them!

TOTBWF avatar Jan 25 '23 23:01 TOTBWF

Did they (the gnarly bugs) ever get fixed?

jamesmckinna avatar Sep 25 '23 07:09 jamesmckinna

If not, could you push the README file as is, and comment out the buggy examples with explanations?

MatthewDaggitt avatar Sep 26 '23 00:09 MatthewDaggitt

Sorry, this fell off my radar for a bit: I'll refresh myself on the details tomorrow

TOTBWF avatar Sep 26 '23 00:09 TOTBWF

Regarding gnarly scoping issues... see also #2192 ?

jamesmckinna avatar Dec 14 '23 11:12 jamesmckinna

Tried to add a README file to this, and have found that it has bit rotted massively... I now get the following error:

An internal error has occurred. Please report this as a bug.
Location of the error: __IMPOSSIBLE__, called at src/full/Agda/TypeChecking/Unquote.hs:509:79 in Agda-2.6.4-e6510447f87a1a26375f0a932139120d3050d11d5f869249fbd6acc3a8abb596:Agda.TypeChecking.Unquote

MatthewDaggitt avatar Mar 03 '24 05:03 MatthewDaggitt

It seems such a shame but I think I might be closing this next week unless we hear from @TOTBWF.

MatthewDaggitt avatar Mar 03 '24 05:03 MatthewDaggitt