HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Package0.5.1DataDependent Types

vec

Vec: length-indexed (sized) list

Modules

4 modules
  • Data.Vec.DataFamily.SpineStrict49Spine-strict length-indexed list defined as data-family: Vec. Data family variant allows lazy pattern matching.
  • Data.Vec.Lazy54Lazy (in elements and spine) length-indexed list: Vec.
  • Data.Vec.Lazy.Inline47A variant of Data.Vec.Lazy with functions written using SNatI.
  • Data.Vec.Pull36Pull/representable Vec n a = Fin n -> a. The module tries to have same API as Data.Vec.Lazy, missing bits:

Description

This package provides length-indexed (sized) lists, also known as vectors.

data Vec n a where VNil :: Vec 'Nat.Z a (:::) :: a -> Vec n a -> Vec ('Nat.S n) a

The functions are implemented in four flavours:

naive: with explicit recursion. It's simple, constraint-less, yet slow. pull: using Fin n -> a representation, which fuses well, but makes some programs hard to write. And data-family: which allows lazy pattern matching inline: which exploits how GHC dictionary inlining works, unrolling recursion if the size of Vec is known statically.

As best approach depends on the application, vec doesn't do any magic transformation. Benchmark your code.

This package uses fin, i.e. not GHC.TypeLits, for indexes.

For lens or optics support see vec-lens and vec-optics packages respectively.

See Hasochism: the pleasure and pain of dependently typed haskell programming by Sam Lindley and Conor McBride for answers to how and why. Read APLicative Programming with Naperian Functors by Jeremy Gibbons for (not so) different ones.

linear has V type, which uses Vector from vector package as backing store. Vec is a real GADT, but tries to provide as many useful instances (upto lens). vector-sized Great package using GHC.TypeLits. Current version (0.6.1.0) uses finite-typelits and Int indexes. sized-vector depends on singletons package. vec isn't light on dependencies either, but try to provide wide GHC support. fixed-vector sized also depends on a singletons package. The Sized f n a type is generalisation of linear's V for any ListLike. clash-prelude is a kitchen sink package, which has CLaSH.Sized.Vector module. Also depends on singletons.

Depends on

11 packages

Used by in this set · 1