{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreih45qnecoeudnpjapzytpsz7c5fgxg65u4ukori2ipxgfcoh6sdii",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mlqsgjv7xog2"
  },
  "path": "/t/knownnat-indexed-vectors/14099#post_2",
  "publishedAt": "2026-05-13T16:50:20.000Z",
  "site": "https://discourse.haskell.org",
  "tags": [
    "@m",
    "@n"
  ],
  "textContent": "I’m highly interested in this given I’ve been dealing with vectors matrices and tensors lately. Fun stuff.\n\nI’ve been taking an approach that uses a type family to dispatch to a specific implementation for efficiency. It works, but that is about all I can say about it - I more or less took my functor / foldable / traversable implementation straight from `vector`, so its not very fancy.\n\n\n    type family V (n :: Nat) (a :: Type) :: Type where\n        V 0 a = V0 a\n        V 1 a = V1 a\n        V 2 a = V2 a\n        V 3 a = V3 a\n        -- ...\n        V n a = BigV n a\n\n    data V0 a = V0\n\n    data V1 a = V1\n        {-# UNPACK #-} !a\n\n    data V2 a = V2\n        {-# UNPACK #-} !a\n        {-# UNPACK #-} !a\n\n    data V3 a = V3\n        {-# UNPACK #-} !a\n        {-# UNPACK #-} !a\n        {-# UNPACK #-} !a\n\n    -- MemVector is roughly ~ Ptr (MemRep a), from my `memalloc` -backed vector classes\n    newtype BigV (n :: Nat) a = BigV (MemVector n a)\n\n\nmixphix:\n\n> In this case the instances map/fold/traverse over both of the `dimensions`, `@m` and `@n`. What’s more, the Kronecker product is super easy to exhibit",
  "title": "KnownNat-indexed vectors"
}