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
| forever : ℕ → ℕ | |
| forever zero = zero | |
| forever (succ n) = forever (succ (succ n)) |
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
| _*_ : ℕ → ℕ → ℕ | |
| zero * n = zero | |
| (succ m) * n = n + (m * n) | |
| factorial : ℕ → ℕ | |
| factorial zero = succ zero | |
| factorial (succ n) = (succ n) * (factorial n) |
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
| data List (A : Set) : Set where | |
| [] : List A | |
| _::_ : A → List A → List A |
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
| {-# BUILTIN NATURAL ℕ #-} | |
| {-# BUILTIN ZERO zero #-} | |
| {-# BUILTIN SUC succ #-} |
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
| open import Nat | |
| onetwothree : List ℕ | |
| onetwothree = 1 :: (2 :: (3 :: [])) |
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
| length₀ : (A : Set) → List A → ℕ | |
| length₀ _ [] = zero | |
| length₀ A (a :: l) = succ (length₀ A l) |
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
| length : {A : Set} → List A → ℕ | |
| length [] = zero | |
| length (a :: l) = succ (length l) |
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
| _++_ : {A : Set} → List A → List A → List A | |
| [] ++ l = l | |
| (a :: xs) ++ l = a :: (xs ++ l) | |
| reverse : {A : Set} → List A → List A | |
| reverse [] = [] | |
| reverse (a :: l) = (reverse l) ++ (a :: []) |
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
| _map_ : {A B : Set} → List A → (A → B) → List B | |
| [] map _ = [] | |
| (a :: xs) map f = (f a) :: (xs map f) | |
| twothreefour : List ℕ | |
| twothreefour = onetwothree map succ |
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
| _flatMap_ : {A B : Set} → List A → (A → List B) → List B | |
| [] flatMap _ = [] | |
| (a :: xs) flatMap f = (f a) ++ (xs flatMap f) |