Created
September 4, 2022 23:44
-
-
Save oisdk/8e80a1600ca9bacdd8a005432ad33b03 to your computer and use it in GitHub Desktop.
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
primes : ∀ n → List (Fin n) | |
primes zero = [] | |
primes (suc zero) = [] | |
primes (suc (suc zero)) = [] | |
primes (suc (suc (suc m))) = sieve (tabulate (just ∘ Fin.suc)) | |
where | |
cross-off : ∀ {n} → Fin _ → Vec (Maybe _) n → Vec (Maybe _) n | |
sieve : ∀ {n} → Vec (Maybe (Fin (2 + m))) n → List (Fin (3 + m)) | |
sieve [] = [] | |
sieve (nothing ∷ xs) = sieve xs | |
sieve (just x ∷ xs) = suc x ∷ sieve (cross-off x xs) | |
cross-off p fs = foldr B f (const []) fs p | |
where | |
B = λ n → ∀ {i} → Fin i → Vec (Maybe (Fin (2 + m))) n | |
f : ∀ {n} → Maybe (Fin (2 + m)) → B n → B (suc n) | |
f _ xs zero = nothing ∷ xs p | |
f x xs (suc y) = x ∷ xs y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment