9||| Heterogeneous vectors where the type index gives, element-wise,
10||| the types of the contents.
11data HVect : Vect k Type -> Type where
13 (::) : t -> HVect ts -> HVect (t::ts)
15||| Extract an element from an HVect
16index : (i : Fin k) -> HVect ts -> index i ts
18index (FS j) (x::xs) = index j xs
20deleteAt : (i : Fin (S l)) -> HVect us -> HVect (deleteAt i us)
21deleteAt FZ (x::xs) = xs
22deleteAt {l = S m} (FS j) (x::xs) = x :: deleteAt j xs
23deleteAt {l = Z} (FS j) (x::xs) = absurd j
24deleteAt _ [] impossible
26replaceAt : (i : Fin k) -> t -> HVect ts -> HVect (replaceAt i t ts)
27replaceAt FZ y (x::xs) = y::xs
28replaceAt (FS j) y (x::xs) = x :: replaceAt j y xs
30updateAt : (i : Fin k) -> (index i ts -> t) -> HVect ts -> HVect (replaceAt i t ts)
31updateAt FZ f (x::xs) = f x :: xs
32updateAt (FS j) f (x::xs) = x :: updateAt j f xs
34||| Append two `HVect`s.
35(++) : HVect ts -> HVect us -> HVect (ts ++ us)
37(++) (x::xs) ys = x :: (xs ++ ys)
39instance Eq (HVect []) where
42instance (Eq t, Eq (HVect ts)) => Eq (HVect (t::ts)) where
43 (x::xs) == (y::ys) = x == y && xs == ys
45class Shows (k : Nat) (ts : Vect k Type) where
46 shows : HVect ts -> Vect k String
48instance Shows Z [] where
51instance (Show t, Shows k ts) => Shows (S k) (t::ts) where
52 shows (x::xs) = show x :: shows xs
54instance (Shows k ts) => Show (HVect ts) where
55 show xs = "[" ++ (pack . intercalate [','] . map unpack . toList $ shows xs) ++ "]"
57||| Extract an arbitrary element of the correct type.
59get : {default tactics { search 100; } p : Elem t ts} -> HVect ts -> t
60get {p = Here} (x::xs) = x
61get {p = There p'} (x::xs) = get {p = p'} xs
63||| Replace an element with the correct type.
64put : {default tactics { search 100; } p : Elem t ts} -> t -> HVect ts -> HVect ts
65put {p = Here} y (x::xs) = y :: xs
66put {p = There p'} y (x::xs) = x :: put {p = p'} y xs
68||| Update an element with the correct type.
69update : {default tactics { search 100; } p : Elem t ts} -> (t -> u) -> HVect ts -> HVect (replaceByElem ts p u)
70update {p = Here} f (x::xs) = f x :: xs
71update {p = There p'} f (x::xs) = x :: update {p = p'} f xs
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