BSD-3-Clause licensed by Oleg Grenrus
Maintained by Oleg.Grenrus
This version can be pinned in stack with:vec-0.5@sha256:1c2d4e4a8af0169df00201950595fe70324cfcd2ec279d2259aba9b0980eb747,6067

Module documentation for 0.5

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.

Similar packages

  • 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 ( 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.


Revision history for vec


  • Remove PigeonHole module. It didn’t work well.


  • Add boring instances
  • Add dfoldr, dfoldl and dfoldl'
  • Implement Lazy.reverse using dfoldl


  • Support fin-0.2
  • Add indexed-traversable instances
  • Explicitly mark all modules as Safe or Trustworthy.
  • Add Eq1, Ord1 and Show1 instances
  • Add init, last and toNonEmpty

  • Fix product


  • Split lens utilities into vec-lens package.
  • Add snoc and reverse operations
  • Add repeat
  • Drop dependency on base-compat
  • Add explicit tabulate


  • Add Data.Vec.DataFamily.SpineStrict.gix
  • Add Data.Vec.DataFamily.SpineStrict.ix requires InlineInduction

  • Use fin-0.1


  • Add Data.Vec.DataFamily.SpineStrict module
  • Add Data.Vec.DataFamily.SpineStrict.Pigeonhole module: this let us define Representable in a handy way.


  • Reverse dependencies with boring.
  • GHC-8.4.1 support


  • First version. Released on an unsuspecting world.