Last active
August 3, 2016 19:34
-
-
Save useronym/8ade27a8c6d97237e15700f9c07b4b90 to your computer and use it in GitHub Desktop.
This file contains 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
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