1
------------------------------------------------------------------------
2
-- Vectors defined in terms of Data.Star
3
------------------------------------------------------------------------
5
module Data.Star.Vec where
8
open import Data.Star.Nat
9
open import Data.Star.Fin using (Fin)
10
open import Data.Star.Decoration
11
open import Data.Star.Pointer as Pointer hiding (lookup)
12
open import Data.Star.List using (List)
13
open import Relation.Binary
14
open import Relation.Binary.Consequences
15
open import Data.Function
18
-- The vector type. Vectors are natural numbers decorated with extra
19
-- information (i.e. elements).
26
[] : ∀ {a} → Vec a zero
31
_∷_ : ∀ {a n} → a → Vec a n → Vec a (suc n)
36
head : ∀ {a n} → Vec a (1# + n) → a
39
tail : ∀ {a n} → Vec a (1# + n) → Vec a n
46
_++_ : ∀ {a m n} → Vec a m → Vec a n → Vec a (m + n)
51
lookup : ∀ {a n} → Fin n → Vec a n → a
52
lookup i xs with Pointer.lookup i xs
55
------------------------------------------------------------------------
58
fromList : ∀ {a} → (xs : List a) → Vec a (length xs)
60
fromList (x ◅ xs) = x ∷ fromList xs
62
toList : ∀ {a n} → Vec a n → List a
63
toList = gmap (const tt) decoration