Cons :: a -> [a] -> DList a
A unidirectional pattern synonym for cons. This is implemented with toList.
A difference list is an abstraction representing a list that
supports \mathcal{O}(1) append and snoc operations. This module
provides the type for a difference list, DList, and a collection of supporting
functions for (a) converting to and from lists and (b) operating on DLists
efficiently.
Cons :: a -> [a] -> DList aA unidirectional pattern synonym for cons. This is implemented with toList.
Nil :: DList aA unidirectional pattern synonym for empty. This is implemented with toList.
newtype DList aA difference list is an abstraction representing a list that
supports \mathcal{O}(1) append and snoc operations, making it
useful for replacing frequent applications of ++ such as logging and pretty
printing (esp. if those uses of ++ are left-nested).
fromList :: [a] -> DList afromList xs is a DList representing the list xs.
fromList obeys the laws:
'toList' . __fromList__ = 'id'
__fromList__ . 'toList' = 'id'
This function is implemented with ++. Repeated uses of fromList 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
DList representation and library:
__fromList__ . f . 'toList'
More likely, you will convert from a list, perform some operation on the
DList, and convert back to a list:
'toList' . g . __fromList__
toList :: DList a -> [a]toList xs is the list represented by xs.
toList obeys the laws:
__toList__ . 'fromList' = 'id'
'fromList' . __toList__ = 'id'
Evaluating toList xs may “collapse” the chain of function composition
underlying many DList functions (append in particular) used to construct
xs. This may affect any efficiency you achieved due to laziness in the
construction.
apply :: DList a -> [a] -> [a]apply xs ys is the list represented by the xs after appending
ys to it.
\mathcal{O}(1).
apply obeys the law:
__apply__ xs ys = 'toList' xs '++' ys
empty :: DList aempty is a DList with no elements.
empty obeys the law:
'toList' __empty__ = []
singleton :: a -> DList asingleton x is a DList with the single element x.
singleton obeys the law:
'toList' (__singleton__ x) = [x]
cons :: a -> DList a -> DList asnoc :: DList a -> a -> DList asnoc xs x is a DList with the initial DList xs and the last
element x.
\mathcal{O}(1).
snoc obeys the law:
'toList' (__snoc__ xs x) = 'toList' xs '++' [x]
append :: DList a -> DList a -> DList aappend xs ys is a DList obtained from the concatenation of the elements
of xs and ys.
\mathcal{O}(1).
append obeys the law:
'toList' (__append__ xs ys) = 'toList' xs '++' 'toList' ys
concat :: [DList a] -> DList aconcat xss is a DList representing the concatenation of all DLists in
the list xss.
\mathcal{O}().length xss
concat obeys the law:
'toList' (__concat__ xss) = 'List.concat' ('List.map' 'toList' xss)
replicate :: Int -> a -> DList areplicate n x is a DList of length n with x as the value of
every element.
\mathcal{O}(n).
replicate obeys the law:
'toList' (__replicate__ n x) = 'List.replicate' n x
head :: DList a -> ahead xs is the first element of xs. If xs is empty, an error is
raised.
\mathcal{O}(1).
head obeys the law:
__head__ xs = 'List.head' ('toList' xs)
tail :: DList a -> [a]tail xs is a list of the elements in xs excluding the first element.
If xs is empty, an error is raised.
\mathcal{O}().length (toList xs)
tail obeys the law:
__tail__ xs = 'List.tail' ('toList' xs)
unfoldr :: (b -> Maybe (a, b)) -> b -> DList aunfoldr f z is the DList 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:
'toList' (__unfoldr__ f z) = 'List.unfoldr' f z
foldr :: (a -> b -> b) -> b -> DList a -> bfoldr f z xs is the right-fold of f over xs.
\mathcal{O}().length (toList xs)
foldr obeys the law:
__foldr__ f z xs = 'List.foldr' f z ('toList' xs)
map :: (a -> b) -> DList a -> DList bmap f xs is the DList obtained by applying f to each element of
xs.
\mathcal{O}().length (toList xs)
map obeys the law:
'toList' (__map__ f xs) = 'List.map' f ('toList' xs)
intercalate :: DList a -> [DList a] -> DList aintercalate xs xss is the concatenation of xss after the insertion
of xs between every pair of
elements.
\mathcal{O}().length xss
intercalate obeys the law:
'toList' (__intercalate__ xs xss) = 'List.intercalate' ('toList' xs) ('map' 'toList' xss)
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