BSD-3-Clause licensed and maintained by Henning Thielemann
This version can be pinned in stack with:non-empty-0.3.5@sha256:f76ff0894f2adcd250bda0600114d510f2ded475dfdbd2700060994355f23297,3739

We provide the data type NonEmpty that allows to store a list-like structure with at least or exactly n elements, where n is fixed in the type in a kind of Peano encoding and is usually small. The datatype is intended to increase safety by making functions total that are partial on plain lists. E.g. on a non-empty list, head and tail are always defined.

There are more such data types like Optional and Empty. Together with NonEmpty you can define a list type for every finite set of admissible list lengths.

The datatype can be combined with Lists, Sequences and Sets (from the containers package).

The package needs only Haskell 98.

Similar packages:

  • semigroups, semigroupoids: restricted to lists, minimum number of elements: 1, provides more type classes tailored to the use of non-empty lists.

  • NonEmptyList: restricted to lists, minimum number of elements: 1

  • NonEmpty: restricted to lists, minimum number of elements: 1, designed for unqualified use of identifiers

  • Cardinality:NeverEmptyList

  • mono-traversable:Data.MinLen: allows to specify a minimum number of elements using type families and works also for monomorphic data structures like ByteString

  • http://www.haskell.org/haskellwiki/Non-empty_list

Related packages:

  • Stream: Lists that contain always infinitely many elements.

  • fixed-length: Uses the data structure of this package and defines a closed-world class for fixed-length lists and an according index type.

  • fixed-list: Uses the same data structure as this package but is intended for fixing the number of elements in a list. Requires multi-parameter type classes with functional dependencies.