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

Case split with non-trivial RHS should either be disallowed or do the right thing #2800

Open
jespercockx opened this issue Oct 11, 2017 · 5 comments
Labels
scope Issues relating to scope checking type: bug Issues and pull requests about actual bugs ux: case splitting Issues relating to the case split ("C-c C-c") command ux: interaction Issues to do with interactive development (holes, case splitting, etc)
Milestone

Comments

@jespercockx
Copy link
Member

jespercockx commented Oct 11, 2017

Currently, Agda allows me to perform a case split on x in this example:

open import Agda.Builtin.Nat

postulate foo : Nat  Nat  Nat

bar : Nat  Nat
bar x = foo x {!x!}

However, the resulting code is not type-correct:

bar : Nat  Nat
bar zero = foo x ?
bar (suc x) = foo x ?
-- Not in scope:
--   x

We should either disallow this again or (preferably) substitute x with zero and suc x in the respective clauses.

@jespercockx jespercockx added ux: case splitting Issues relating to the case split ("C-c C-c") command ux: interaction Issues to do with interactive development (holes, case splitting, etc) labels Oct 11, 2017
@andreasabel
Copy link
Member

andreasabel commented Oct 11, 2017

This is a known problem. Originally, one could not even split if the rhs was more than a single hole. Now, you can split, but in some cases you get garbage. I still consider this an improvement.

The problem is mostly on the side of the emacs mode (see #2340), but in your case, there is also the substitution into the rhs missing. However, at this point we cannot reify internal syntax to concrete syntax in a way that fulfills the roundtrip-property, thus, a perfect implementation of case splitting is impossible.

@UlfNorell : refering to our discussion yesterday, here is a situation where you want the round-trip property, which is currently impossible (e.g. because of the desugaring of lets), and it will not get better with more things that are desugared early.

@andreasabel
Copy link
Member

Maybe a possible solution here would be to put the content of rhss into holes. However, emacs does not know where the rhs of a clause ends.

@gallais
Copy link
Member

gallais commented Oct 12, 2017

What about using an @ alias to keep the name we are case-splitting on if it shows up on the right hand side?

bar : Nat  Nat
bar x = foo x {!x!}

would lead to:

bar : Nat  Nat
bar x@zero = foo x ?
bar x@(suc x') = foo x ?

@gallais gallais added the scope Issues relating to scope checking label Oct 12, 2017
@andreasabel
Copy link
Member

Ah, yes, this would fix the present issue!

@UlfNorell UlfNorell added type: bug Issues and pull requests about actual bugs ux: emacs Issues relating to the Emacs agda2-mode and removed ux: emacs Issues relating to the Emacs agda2-mode labels May 29, 2018
@UlfNorell
Copy link
Member

The other issues in the family: #1146 and #2628.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope Issues relating to scope checking type: bug Issues and pull requests about actual bugs ux: case splitting Issues relating to the case split ("C-c C-c") command ux: interaction Issues to do with interactive development (holes, case splitting, etc)
Projects
None yet
Development

No branches or pull requests

4 participants