Skip to content

Instantly share code, notes, and snippets.

@tsani
Created September 4, 2019 19:42
Show Gist options
  • Save tsani/35c369f7153fd606a1d8698ea1d55b38 to your computer and use it in GitHub Desktop.
Save tsani/35c369f7153fd606a1d8698ea1d55b38 to your computer and use it in GitHub Desktop.
all' : (a -> Bool) -> List a -> Bool
all' f [] = True
all' f (x :: xs) = f x && all' f xs
allLemma : f x = True -> all' f xs = True -> all' f (x :: xs) = True
allLemma p1 p2 = rewrite p1 in rewrite p2 in Refl
allFiltered : (f : a -> Bool) -> (xs : List a) -> all' f (filter f xs) = True
allFiltered f [] = Refl
allFiltered f (x :: xs) = lemma (allFiltered f xs) (f x) Refl where
lemma : all' f (filter f xs) = True -> (b : Bool) -> b = f x -> all' f (filter f (x :: xs)) = True
lemma p False p2 =
rewrite sym p2 in p
lemma p True p2 = rewrite sym p2 in allLemma (sym p2) p
@tsani
Copy link
Author

tsani commented Sep 10, 2019

Oh my god, this is incredible! It's like Idris has the "inspect" pattern from Agda built right in! Thanks for showing me

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