Add an 'iterate' function to Utils

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2024-02-11 14:16:42 -08:00
parent ec31333e9a
commit 6fe8dc2a02
1 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
module Utils where
open import Data.Nat using (; suc)
open import Data.List using (List; []; _∷_; _++_)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.List.Relation.Unary.All using (All; []; _∷_; map)
@ -34,3 +35,7 @@ All¬-¬Any {l = x ∷ xs} (_ ∷ ¬Pxs) (there Pxs) = All¬-¬Any ¬Pxs Pxs
All-x∈xs : ∀ {a} {A : Set a} (xs : List A) → All (λ x → x ∈ xs) xs
All-x∈xs [] = []
All-x∈xs (x ∷ xs') = here refl ∷ map there (All-x∈xs xs')
iterate : ∀ {a} {A : Set a} (n : ) → (f : A → A) → A → A
iterate 0 _ a = a
iterate (suc n) f a = f (iterate n f a)