6data BoundedList : Type -> Nat -> Type where
8 (::) : a -> BoundedList a n -> BoundedList a (S n)
10length : BoundedList a n -> Fin (S n)
12length (x :: xs) = fS (length xs)
14--------------------------------------------------------------------------------
15-- Indexing into bounded lists
16--------------------------------------------------------------------------------
18index : Fin (S n) -> BoundedList a n -> Maybe a
20index fO (x :: _) = Just x
21index (fS f) (_ :: xs) = index f xs
23--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
27weaken : BoundedList a n -> BoundedList a (n + m)
29weaken (x :: xs) = x :: weaken xs
31--------------------------------------------------------------------------------
32-- Conversions to and from list
33--------------------------------------------------------------------------------
35take : (n : Nat) -> List a -> BoundedList a n
38take (S n') (x :: xs) = x :: take n' xs
40toList : BoundedList a n -> List a
42toList (x :: xs) = x :: toList xs
44fromList : (xs : List a) -> BoundedList a (length xs)
46fromList (x :: xs) = x :: fromList xs
48--------------------------------------------------------------------------------
49-- Building (bigger) bounded lists
50--------------------------------------------------------------------------------
52replicate : (n : Nat) -> a -> BoundedList a n
54replicate (S n) x = x :: replicate n x
56--------------------------------------------------------------------------------
58--------------------------------------------------------------------------------
60foldl : (a -> b -> a) -> a -> BoundedList b n -> a
62foldl f e (x::xs) = foldl f (f e x) xs
64foldr : (a -> b -> b) -> b -> BoundedList a n -> b
66foldr f e (x::xs) = f x (foldr f e xs)
68--------------------------------------------------------------------------------
70--------------------------------------------------------------------------------
72map : (a -> b) -> BoundedList a n -> BoundedList b n
74map f (x :: xs) = f x :: map f xs
76--------------------------------------------------------------------------------
78--------------------------------------------------------------------------------
80%assert_total -- not sure why this isn't accepted - clearly decreasing on n
81pad : (xs : BoundedList a n) -> (padding : a) -> BoundedList a n
83pad {n=S n'} [] padding = padding :: (pad {n=n'} [] padding)
84pad {n=S n'} (x :: xs) padding = x :: pad {n=n'} xs padding
87--------------------------------------------------------------------------------
89--------------------------------------------------------------------------------
91zeroBoundIsEmpty : (xs : BoundedList a 0) -> xs = the (BoundedList a 0) []
92zeroBoundIsEmpty [] = refl
93zeroBoundIsEmpty (_ :: _) impossible
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list