Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically delete redundant cases/equations #135

Open
lastland opened this issue Nov 3, 2020 · 5 comments
Open

Automatically delete redundant cases/equations #135

lastland opened this issue Nov 3, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@lastland
Copy link
Collaborator

lastland commented Nov 3, 2020

Issue by antalsz
Friday Jun 28, 2019 at 05:33 GMT
Originally opened as antalsz/hs-to-coq#135


Sometimes, when using skip constructor, we'll be left with redundant cases. For example:

hasSomeUnfolding :: Unfolding -> Bool
hasSomeUnfolding NoUnfolding   = False
hasSomeUnfolding BootUnfolding = False
hasSomeUnfolding _             = True

If we skip every constructor except for NoUnfolding, the resulting Coq code is

Definition hasSomeUnfolding : Unfolding -> bool :=
  fun arg_0__ => match arg_0__ with | NoUnfolding => false | _ => true end.

But since our data type has only one constructor, Coq will reject this because the _ => true case is redundant. We can work around this with skip equation or skip case pattern, but could we instead infer this automatically?

(Examples and motivation from #130)

@lastland lastland added the enhancement New feature or request label Nov 3, 2020
@lastland
Copy link
Collaborator Author

lastland commented Nov 3, 2020

Comment by nomeata
Friday Jun 28, 2019 at 08:45 GMT


I think this should be possible. We have code like isCompleteMultiPattern that checks if patterns are comple, and whether to add a catch-all case. I expect that the same or similar code can be used to check if an existing catch-call case can be dropped.

@lastland
Copy link
Collaborator Author

lastland commented Nov 3, 2020

Comment by antalsz
Friday Jun 28, 2019 at 15:44 GMT


I looked into using that, but the naïve way of reusing it produces quadratic code (check every prefix), and this solution seemed like it’d be quicker to pull together.

Although, if we only check the last case for redundancy, and then if that was redundant check the preceding case, we’d catch some of the problems – maybe enough?

@lastland
Copy link
Collaborator Author

lastland commented Nov 3, 2020

Comment by nomeata
Friday Jun 28, 2019 at 16:40 GMT


Yes, this might work:

  1. split off a catch-all pattern in the original code, if it is there
  2. check the other patterns for completeness
  3. if not complete, add the existing catch-all. If there was none, add the default catch-call.

@lastland
Copy link
Collaborator Author

lastland commented Nov 3, 2020

Comment by antalsz
Friday Jun 28, 2019 at 16:43 GMT


We also have to handle each argument separately, but yeah, that seems like a good outline. Particularly if we assume that this is only introduced by skip constructor – otherwise the Haskell code probably doesn’t have redundant cases. And if it is, the redundancy is gonna be in the catch-all case. (If there was other redundancy, well, we still have skip equation and skip case pattern.)

@lastland
Copy link
Collaborator Author

lastland commented Nov 3, 2020

Comment by nomeata
Friday Jun 28, 2019 at 17:06 GMT


We also have to handle each argument separately

You mean in functions with multiple arguments? That’s taken care of, I believe, as isCompleteMultiPattern takes a multi-patern.

otherwise the Haskell code probably doesn’t have redundant cases.

surprisingly :-)

(I had a recollection that I had to prune redundant catch-all cases at the end, but looking at the code that does not seem to be true. Which is good.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant