vec: Vec: length-indexed (sized) list

[ bsd3, data, dependent-types, library ] [ Propose Tags ] [ Report a vulnerability ]

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 three 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

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

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

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0, 0.1, 0.1.1, 0.1.1.1, 0.2, 0.3, 0.4, 0.4.1, 0.5, 0.5.1
Change log ChangeLog.md
Dependencies adjunctions (>=4.3 && <4.4), base (>=4.7 && <4.11), base-compat (>=0.9.3 && <0.10), boring (<0.1), deepseq (>=1.3.0.2 && <1.5), distributive (>=0.5.3 && <0.6), fin (<0.1), hashable (>=1.2.6.1 && <1.3), lens (>=4.15.4 && <4.16), semigroupoids (>=5.2.1 && <5.3), semigroups (>=0.18.3 && <0.18.4) [details]
Tested with ghc ==7.8.4, ghc ==7.10.3, ghc ==8.0.2, ghc ==8.2.1
License BSD-3-Clause
Copyright (c) 2017 Oleg Grenrus
Author Oleg Grenrus <oleg.grenrus@iki.fi>
Maintainer Oleg.Grenrus <oleg.grenrus@iki.fi>
Revised Revision 1 made by phadej at 2017-11-29T19:25:48Z
Category Data
Home page https://github.com/phadej/vec
Bug tracker https://github.com/phadej/vec/issues
Source repo head: git clone https://github.com/phadej/vec.git
Uploaded by phadej at 2017-11-21T12:18:19Z
Distributions Arch:0.5, LTSHaskell:0.5, NixOS:0.5, Stackage:0.5.1
Reverse Dependencies 5 direct, 7896 indirect [details]
Downloads 6051 total (80 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-11-21 [all 1 reports]