Tutorial
Tutorials.Thursday
Tutorials.Thursday{-# OPTIONS --allow-unsolved-metas --guardedness #-}
import Tutorials.Monday as Mon
import Tutorials.Tuesday as Tue
import Tutorials.Wednesday as Wed
open Mon using (⊤; tt; ℕ; zero; suc)
open Mon.Simple using (_⊎_; inl; inr)
open Tue.Product using (Σ; _,_; fst; snd; _×_)
module Tutorials.Thursday where
variable
A B C S : Set
module WithAbstraction where
open Mon using (Bool; true; false; Pred; _≡_; refl; _+_; subst; +-comm)
open Mon.List using (List; []; _∷_)
filter : (A → Bool) → List A → List A
filter f [] = []
filter f (x ∷ xs) with f x
filter f (x ∷ xs) | true = x ∷ filter f xs
filter f (x ∷ xs) | false = filter f xs
filter′ : (A → Bool) → List A → List A
filter′ f [] = []
filter′ f (x ∷ xs) with f x
... | true = x ∷ filter′ f xs
... | false = filter′ f xs
thm : {P : Pred ℕ} (n m : ℕ) → P (n + m) → P (m + n)
thm n m p with n + m | +-comm n m
thm n m p | .(m + n) | refl = p
thm′ : {P : Pred ℕ} (n m : ℕ) → P (n + m) → P (m + n)
thm′ n m p rewrite +-comm n m = p
thm′′ : {P : Pred ℕ} (n m : ℕ) → P (n + m) → P (m + n)
thm′′ {P} n m p = subst {P = P} (+-comm n m) p
ListT : Set → Set → Set
ListT X B = ⊤ ⊎ (X × B)
module List where
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
mkList : ListT A (List A) → List A
mkList x = {!!}
foldr : (ListT A B → B) → List A → B
foldr alg xs = {!!}
list-id : List A → List A
list-id = {!!}
incr : ListT A ℕ → ℕ
incr x = {!!}
length : List A → ℕ
length = {!!}
module CoList where
record CoList (A : Set) : Set where
coinductive
field
next : ListT A (CoList A)
open CoList
[] : CoList A
[] = {!!}
_∷_ : A → CoList A → CoList A
(x ∷ xs) = {!!}
unfoldr : (S → ListT A S) → S → CoList A
unfoldr coalg s = {!!}
colist-id : CoList A → CoList A
colist-id = {!!}
repeat : A → CoList A
repeat = {!!}
take : ℕ → CoList A → List.List A
take n xs = {!!}
module Stream where
record Stream (A : Set) : Set where
coinductive
field
head : A
tail : Stream A
open Stream
forever : A → Stream A
forever x = {!!}
unfold : (S → A × S) → S → Stream A
unfold coalg s = {!!}