Skip to content

Instantly share code, notes, and snippets.

@larrytheliquid
Last active February 26, 2017 23:48
Show Gist options
  • Save larrytheliquid/c733ffa42a2238c48c4cb1dca5b1fe0d to your computer and use it in GitHub Desktop.
Save larrytheliquid/c733ffa42a2238c48c4cb1dca5b1fe0d to your computer and use it in GitHub Desktop.
Generic representation: https://is.gd/rms0P7
open import Data.Nat
open import Data.Product
open import Data.String
open import Relation.Binary.PropositionalEquality
module _ where
mutual
data Vec₁ (A : Set) : Set where
nil : Vec₁ A
cons : (n : ℕ) → A → (xs : Vec₁ A) → Vec₂ xs ≡ n → Vec₁ A
Vec₂ : {A : Set} → Vec₁ A → ℕ
Vec₂ nil = zero
Vec₂ (cons n x xs q) = suc (Vec₂ xs)
Vec : Set → ℕ → Set
Vec A n = Σ (Vec₁ A) (λ xs → Vec₂ xs ≡ n)
[] : {A : Set} → Vec A zero
[] = nil , refl
infixr 5 _∷_
_∷_ : {A : Set} {n : ℕ} → A → (xs : Vec A n) → Vec A (suc n)
x ∷ (xs , q) = cons _ x xs q , cong suc q
eg : Vec String 3
eg = "a" ∷ "b" ∷ "c" ∷ []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment