Modules 3
Data.DList.DNonEmpty
stableA non-empty difference list is a difference list paired with a head
element. Like the difference list, it supports \mathcal{O}(1)
append and snoc operations.
This module provides the type for a non-empty difference list, DNonEmpty, and
a collection of supporting functions for (a) converting to and from NonEmpty
and DList and (b) operating efficiently on DNonEmpty values. The functions
also retain the non-strict semantics of NonEmpty.
Non-Empty Difference List Type
Conversion
fromNonEmpty :: NonEmpty a -> DNonEmpty a
fromNonEmpty xs is a DNonEmpty representing the NonEmpty xs.
fromNonEmpty obeys the laws:
'toNonEmpty' . __fromNonEmpty__ = 'id'
__fromNonEmpty__ . 'toNonEmpty' = 'id'
As with fromList, this function is implemented with ++. Repeated uses
of fromNonEmpty are just as inefficient as repeated uses of ++. If you find
yourself doing some form of the following (possibly indirectly), you may not be
taking advantage of the DNonEmpty representation and library:
__fromNonEmpty__ . f . 'toNonEmpty'
More likely, you will convert from a NonEmpty, perform some operation on the
DNonEmpty, and convert back to a NonEmpty:
'toNonEmpty' . g . __fromNonEmpty__
toNonEmpty :: DNonEmpty a -> NonEmpty a
toNonEmpty xs is the NonEmpty represented by xs.
toNonEmpty obeys the laws:
__toNonEmpty__ . 'fromNonEmpty' = 'id'
'fromNonEmpty' . __toNonEmpty__ = 'id'
As with toList, evaluating toNonEmpty xs may “collapse” the chain of
function composition underlying many DList functions (append in
particular) used to construct the tail of xs. This may affect any efficiency
you achieved due to laziness in the construction.
toList :: DNonEmpty a -> [a]
toList xs is the non-empty list represented by xs.
toList obeys the law:
__toList__ xs = 'NonEmpty.toList' ('toNonEmpty' xs)
fromList :: [a] -> DNonEmpty a
fromList xs is a DNonEmpty representing the list xs. If xs is
empty, an error is raised.
fromList obeys the law:
__fromList__ xs = 'fromNonEmpty' ('NonEmpty.fromList' xs)
Basic Functions
singleton :: a -> DNonEmpty a
singleton x is a DNonEmpty with the single element x.
singleton obeys the law:
'toNonEmpty' (__singleton__ x) = x 'NonEmpty.:|' []
cons :: a -> DNonEmpty a -> DNonEmpty a
snoc :: DNonEmpty a -> a -> DNonEmpty a
snoc xs x is a DNonEmpty with the initial DNonEmpty xs and the
last element x.
\mathcal{O}(1).
snoc obeys the law:
'toNonEmpty' (__snoc__ xs x) = 'toNonEmpty' xs 'Semigroup.<>' (x 'NonEmpty.:|' [])
append :: DNonEmpty a -> DNonEmpty a -> DNonEmpty a
append xs ys is a DNonEmpty obtained from the concatenation of the
elements of xs and ys.
\mathcal{O}(1).
append obeys the law:
'toNonEmpty' (__append__ xs ys) = 'toNonEmpty' xs 'Semigroup.<>' 'toNonEmpty' ys
head :: DNonEmpty a -> a
head xs is the first element of xs.
\mathcal{O}(1).
head obeys the law:
__head__ xs = 'NonEmpty.head' ('toNonEmpty' xs)
tail :: DNonEmpty a -> DList a
tail xs is a DList of the elements in xs excluding the first
element.
\mathcal{O}(1).
tail obeys the law:
'DList.toList' (__tail__ xs) = 'NonEmpty.tail' ('toNonEmpty' xs)
unfoldr :: (b -> (a, Maybe b)) -> b -> DNonEmpty a
unfoldr f z is the DNonEmpty constructed from the recursive application
of f. The recursion starts with the seed value z and ends when, for
some z' : b, f z' == .Nothing
\mathcal{O}().length (unfoldr f z)
unfoldr obeys the law:
'toNonEmpty' (__unfoldr__ f z) = 'NonEmpty.unfoldr' f z
map :: (a -> b) -> DNonEmpty a -> DNonEmpty b
map f xs is the DNonEmpty obtained by applying f to each element
of xs.
\mathcal{O}().length (toNonEmpty xs)
map obeys the law:
'toNonEmpty' (__map__ f xs) = 'NonEmpty.map' f ('toNonEmpty' xs)
- Maintainer
- sean.leather@gmail.com
- Copyright
- © 2017-2020 Oleg Grenrus, 2020 Sean Leather
- License
- BSD-3-Clause
Build record and source files
Community contribution. The service has not verified this documentation. The generator reported 3 diagnostics.
Target: Linux on x86-64. Some inferred types and resolved links are not available.
Generator: aihc-haddock-858b1951-web-1
Metadata snapshot: 5c399ad10bb66f19688f6a371c5eed4c6542a2a6e4873a65871c1260a56b6173
Open the dependency plan · Download the documentation model
- aihc-base-4.21.2.0 · Core library · Cabal file
- aihc-prim-0.13.0 · Core library · Cabal file
- aihc-rts-1.0.2 · Core library · Cabal file
- deepseq-1.5.2.0 · Cabal revision 0 · Cabal file · Source archive
- dlist-1.0 · Cabal revision 2 · Cabal file · Source archive