Created
September 18, 2015 22:15
-
-
Save johnynek/fe0a4e545f2181a6a7ed to your computer and use it in GitHub Desktop.
Filtering a list returns a list that is never bigger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- If the length is < n+1, it is less than n+2 | |
| weakenPair: (p: Fin n ** Vect (finToNat p) a) -> (p1: Fin (S n) ** Vect (finToNat p1) a) | |
| weakenPair (FZ ** v) = (FZ ** v) | |
| weakenPair (FS k ** v) = believe_me (FS k ** v) -- How to prove this branch? | |
| filt : Vect n a -> (fn: a -> Bool) -> (p: Fin (S n) ** Vect (finToNat p) a) | |
| filt [] _ = (0 ** []) | |
| filt (x :: xs) fn with (filt xs fn) | |
| | (p' ** xs') = if (fn x) then ((shift 1 p') ** (x :: xs')) else weakenPair (p' ** xs') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about this:
As a general rule, using functions in a return type can lead to difficulties, so if you can represent things as a data structure instead (e.g. LTE here) things can become easier.