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

With-clause doesn't take advantage of ruled out patterns to normalise #27

Closed
edwinb opened this issue May 20, 2020 · 2 comments
Closed

Comments

@edwinb
Copy link
Collaborator

edwinb commented May 20, 2020

Issue by ohad
Saturday Oct 26, 2019 at 21:04 GMT
Originally opened as edwinb/Idris2-boot#140


I'm not sure this is really a language problem, maybe a feature request?
Potentially related to #139.
Also, the example below is not realistic (because of the go_figure hole), it's just there to illustrate the problem in a short example.

Steps to Reproduce

Foo.idr

foo : Nat -> Bool
foo n = case compare n Z of
          LT => False
          _  => True
          
foo_true : (n : Nat) -> foo n = True
foo_true  n with (compare n Z)
 foo_true n | LT = ?go_figure  -- That's fine
 foo_true n | _  = ?hole       -- That's not

Expected Behavior

$ idris2 Foo.idr
Foo> :t hole
   n : Nat
-------------------------------------
hole : True = True

Observed Behavior

   n : Nat
-------------------------------------
hole : (case _ of { LT => False ; _ => True }) = True

We can, of course, prove the foo_true lemma (modulo go_figure) by exhausting all the other cases:

foo_true' : (n : Nat) -> foo n = True
foo_true'  n with (compare n Z)
 foo_true' n | LT = ?go_figure' -- That's fine
 foo_true' n | GT = Refl         
 foo_true' n | EQ = Refl

But it would be nicer to follow the same pattern that execution takes.

@edwinb
Copy link
Collaborator Author

edwinb commented May 20, 2020

Comment by edwinb
Saturday Dec 07, 2019 at 15:11 GMT


This'd be nice, but would require the normaliser to keep track of a lot of information. I think this is a feature request that's very unlikely to get done, unfortunately. I've added a label, just in case anyone is enthusiastic enough to do it, but my feeling is that it'd be very complicated to achieve.

(My feeling on this sort of thing is often wrong though, so who knows...)

melted pushed a commit to melted/Idris2 that referenced this issue Jun 1, 2020
@edwinb edwinb closed this as completed Jul 16, 2021
@gallais
Copy link
Member

gallais commented Jul 16, 2021

For the record, the typical solution here is to define a view
that has one case for each match of interest & a catchall
constructor for the rest.

Instead of:

foo : s -> ...
foo x = case x of 
  C => ...
  _ => ...

write:

data View s = C | Default

view : (x : s) -> View x
view x = case x of
  C => C
  _ => Default

foo : s -> ...
foo x with (view x)
  foo x | C = ...
  foo x | Default = ...

and you can then prove foo's properties by using the same with (view x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants