Skip to content

Instantly share code, notes, and snippets.

@useronym
Last active August 3, 2016 19:34
Show Gist options
  • Save useronym/8ade27a8c6d97237e15700f9c07b4b90 to your computer and use it in GitHub Desktop.
Save useronym/8ade27a8c6d97237e15700f9c07b4b90 to your computer and use it in GitHub Desktop.
module Fold where
open import Data.Nat.Base using (ℕ; suc)
data List {l} (A : Set l) : Set l where
[] : List A
_::_ : (x : A) → List A → List A
infixr 6 _::_
length : ∀ {l} {A : Set l} → List A → ℕ
length [] = 0
length (x :: xs) = suc (length xs)
fold : {A : Set} (P : List A → Set) → (∀ {a l} → A → P l → P (a :: l)) → P [] → (l : List A) → P l
fold p f init [] = init
fold p f init (x :: xs) = f x (fold p f init xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment