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

Modulemono-traversable-1.0.21.0Haskell2010

Data.NonNull

Data.NonNull extends the concepts from Data.List.NonEmpty to any MonoFoldable.

NonNull is a newtype wrapper for a container with 1 or more elements.

  • 1 type
  • 1 class
  • 27 values
newtypenewtype NonNull mono
#

A monomorphic container that is not null.

Instances15Eq, Data, Ord, Read, Show, Semigroup, …
valueimpureNonNull :: MonoFoldable mono => mono -> NonNull mono
#

Unsafely convert from an unsafe monomorphic container to a safe non-null monomorphic container.

Throws an exception if the monomorphic container is empty.

valuetoNullable :: NonNull mono -> mono
#

Safely convert from a non-null monomorphic container to a nullable monomorphic container.

valuencons :: SemiSequence seq => Element seq -> seq -> NonNull seq
#

Prepend an element to a SemiSequence, creating a non-null SemiSequence.

Generally this uses cons underneath. cons is not efficient for most data structures.

Alternatives:

  • if you don't need to cons, use fromNullable or nonNull if you can create your structure in one go.

  • if you need to cons, you might be able to start off with an efficient data structure such as a NonEmpty List. fromNonEmpty will convert that to your data structure using the structure's fromList function.

classclass MonoFoldable mono => GrowingAppend mono
#

Containers which, when two values are combined, the combined length is no less than the larger of the two inputs. In code:

olength (x <> y) >= max (olength x) (olength y)

This class has no methods, and is simply used to assert that this law holds, in order to provide guarantees of correctness (see, for instance, Data.NonNull).

This should have a Semigroup superclass constraint, however, due to Semigroup only recently moving to base, some packages do not provide instances.

Instances18GrowingAppend, …