4
open import Lib.Prelude
11
data List (A : Set) : Set where
13
_::_ : A -> List A -> List A
15
{-# COMPILED_DATA List [] [] (:) #-}
16
{-# BUILTIN LIST List #-}
17
{-# BUILTIN NIL [] #-}
18
{-# BUILTIN CONS _::_ #-}
20
_++_ : {A : Set} -> List A -> List A -> List A
22
(x :: xs) ++ ys = x :: (xs ++ ys)
24
foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B
26
foldr f z (x :: xs) = f x (foldr f z xs)
28
map : {A B : Set} -> (A -> B) -> List A -> List B
30
map f (x :: xs) = f x :: map f xs
32
map-id : forall {A}(xs : List A) -> map id xs ≡ xs
34
map-id (x :: xs) with map id xs | map-id xs
35
... | .xs | refl = refl
37
data _∈_ {A : Set} : A -> List A -> Set where
38
hd : forall {x xs} -> x ∈ x :: xs
39
tl : forall {x y xs} -> x ∈ xs -> x ∈ y :: xs
41
data All {A : Set}(P : A -> Set) : List A -> Set where
43
_::_ : forall {x xs} -> P x -> All P xs -> All P (x :: xs)
45
head : forall {A}{P : A -> Set}{x xs} -> All P (x :: xs) -> P x
48
tail : forall {A}{P : A -> Set}{x xs} -> All P (x :: xs) -> All P xs
51
_!_ : forall {A}{P : A -> Set}{x xs} -> All P xs -> x ∈ xs -> P x
53
xs ! tl n = tail xs ! n
55
tabulate : forall {A}{P : A -> Set}{xs} -> ({x : A} -> x ∈ xs -> P x) -> All P xs
56
tabulate {xs = []} f = []
57
tabulate {xs = x :: xs} f = f hd :: tabulate (f ∘ tl)
59
mapAll : forall {A B}{P : A -> Set}{Q : B -> Set}{xs}(f : A -> B) ->
60
({x : A} -> P x -> Q (f x)) -> All P xs -> All Q (map f xs)
62
mapAll f h (x :: xs) = h x :: mapAll f h xs
64
mapAll- : forall {A}{P Q : A -> Set}{xs} ->
65
({x : A} -> P x -> Q x) -> All P xs -> All Q xs
66
mapAll- {xs = xs} f zs with map id xs | map-id xs | mapAll id f zs
67
... | .xs | refl | r = r
71
data _⊆_ {A : Set} : List A -> List A -> Set where
73
drop : forall {xs y ys} -> xs ⊆ ys -> xs ⊆ y :: ys
74
keep : forall {x xs ys} -> xs ⊆ ys -> x :: xs ⊆ x :: ys
76
⊆-refl : forall {A}{xs : List A} -> xs ⊆ xs
77
⊆-refl {xs = []} = stop
78
⊆-refl {xs = x :: xs} = keep ⊆-refl
80
_∣_ : forall {A}{P : A -> Set}{xs ys} -> All P ys -> xs ⊆ ys -> All P xs
82
(x :: xs) ∣ drop p = xs ∣ p
83
(x :: xs) ∣ keep p = x :: (xs ∣ p)