Skip to content

Instantly share code, notes, and snippets.

View siddhartha-gadgil's full-sized avatar

Siddhartha Gadgil siddhartha-gadgil

View GitHub Profile
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_::_ : {n : ℕ} → A → Vec A n → Vec A (succ n)
countdown : (n : ℕ) → Vec ℕ (succ n)
countdown zero = zero :: []
countdown (succ m) = (succ m) :: (countdown m)
zipop : {A : Set} → {n : ℕ} → Vec A n → Vec A n → (A → A → A) → Vec A n
zipop [] [] _ = []
zipop (x :: xs) (y :: ys) op = (op x y) :: (zipop xs ys op)
_:+_ : {A : Set} → {n : ℕ} → A → Vec A n → Vec A (succ n)
a :+ [] = a :: []
a :+ (x :: xs) = x :: (a :+ xs)
_contains_ : {A : Set} → List A → (A → Bool) → Bool
[] contains _ = false
(x :: xs) contains p = (p x) || (xs contains p)
if_then_else : {A : Set} → Bool → A → A → A
if true then x else _ = x
if false then _ else y = y
_filter_ : {A : Set} → List A → (A → Bool) → List A
[] filter _ = []
(x :: xs) filter p = if (p x) then (x :: (xs filter p)) else (xs filter p)
fold_by_from_ : {A : Set} → {B : Set} → List A → (A → B → B) → B → B
fold [] by _ from b = b
fold (x :: xs) by op from b = op x (fold xs by op from b)
open import Nat
upto : ℕ → List ℕ
upto zero = []
upto (succ n) = (upto n) ++ ((succ n) :: [])
listsqs : ℕ → List ℕ
listsqs n = upto n map (λ x → (x * x))
sumsqs : ℕ → ℕ
data Option (A : Set) : Set where
Some : A → Option A
None : Option A