Skip to content

Instantly share code, notes, and snippets.

@rybla
Last active August 4, 2022 21:30
Show Gist options
  • Save rybla/0a6e390a0288956f199deb7881e95653 to your computer and use it in GitHub Desktop.
Save rybla/0a6e390a0288956f199deb7881e95653 to your computer and use it in GitHub Desktop.
transpose and identity of vector-matrices in Agda
open import Data.Nat
data Vec : ℕ → Set → Set where
nil : ∀ {A} → Vec 0 A
cons : ∀ {A n} → A → Vec n A → Vec (suc n) A
record Traversable (F : Set → Set) : Set1 where
field
traverse : ∀ {S T : Set} {G : Set → Set} → (S → G T) → F S → G (F T)
open Traversable
postulate
TraversableVec : ∀ {n} → Traversable (Vec n)
TraversableId : Traversable (λ x → x)
TraversableComp : ∀ {F G} → Traversable F → Traversable G → Traversable λ x → F (G x)
idm : ∀ {T m n} → Vec n (Vec m T) → Vec n (Vec m T)
idm {T} {m} {n} v =
traverse
(TraversableComp
-- {λ T → T} {λ T → Vec n (Vec m T)}
TraversableId
(TraversableComp TraversableVec TraversableVec))
{T} {T} {λ x → x}
(λ x → x) v
trans : ∀ {T m n} → Vec n (Vec m T) → Vec m (Vec n T)
trans {T} {m} {n} v = traverse TraversableVec {Vec _ T} {_} {G = λ T → Vec m T} (λ x → x) v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment