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

Modulestrict-list-0.1.7.5Haskell2010

StrictList

Definitions of strict linked list.

Most basic operations like fmap, filter, <*> can only be implemented efficiently by producing an intermediate list in reversed order and then reversing it to the original order. These intermediate reversed functions are exposed by the API, because they very well may be useful for efficient implementations of data-structures built on top of list. E.g., the "deque" package exploits them heavily.

One useful rule of thumb would be that whenever you see that a function has a reversed counterpart, that counterpart is faster and hence if you don't care about the order or intend to reverse the list further down the line, you should give preference to that counterpart.

The typical toList and fromList conversions are provided by means of the Foldable and IsList instances.

  • 1 type
  • 34 values
datadata List a
#

Strict linked list.

Constructors

Instances27Monad, Functor, Applicative, Foldable, Traversable, Alternative, …
valuetoListReversed :: List a -> [a]
#

Convert to lazy list in normal form (with all elements and spine evaluated).

valuetake :: Int -> List a -> List a
#

Leave only the specified amount of elements.

valuedrop :: Int -> List a -> List a
#

Leave only the elements after the specified amount of first elements.

valuefilter :: (a -> Bool) -> List a -> List a
#

Leave only the elements satisfying the predicate.

valuefilterReversed :: (a -> Bool) -> List a -> List a
#

Leave only the elements satisfying the predicate, producing a list in reversed order.

valuetakeWhile :: (a -> Bool) -> List a -> List a
#

Leave only the first elements satisfying the predicate.

valuetakeWhileReversed :: (a -> Bool) -> List a -> List a
#

Leave only the first elements satisfying the predicate, producing a list in reversed order.

valuespan :: (a -> Bool) -> List a -> (List a, List a)
#

An optimized version of the same predicate applied to takeWhile and dropWhile. IOW,

span predicate list = (takeWhile predicate list, dropWhile predicate list)
valuebreak :: (a -> Bool) -> List a -> (List a, List a)
#

An opposite version of span. I.e.,

break predicate = span (not . predicate)
valuematch
  1. :: result
  2. -> element -> List element -> result
  3. -> List element
  4. -> result
#

Pattern match on list using functions.

Allows to achieve all the same as uncons only without intermediate Maybe.

Essentially provides the same functionality as either for Either and maybe for Maybe.

valueuncons :: List a -> Maybe (a, List a)
#

Get the first element and the remainder of the list if it's not empty.

valuehead :: List a -> Maybe a
#

Get the first element, if list is not empty.

valuelast :: List a -> Maybe a
#

Get the last element, if list is not empty.

valuetail :: List a -> List a
#

Get all elements of the list but the first one.

valueinit :: List a -> List a
#

Get all elements but the last one.

valueinitReversed :: List a -> List a
#

Get all elements but the last one, producing the results in reverse order.

valueapZipping :: List (a -> b) -> List a -> List b
#

Apply the functions in the left list to elements in the right one.

valueapZippingReversed :: List (a -> b) -> List a -> List b
#

Apply the functions in the left list to elements in the right one, producing a list of results in reversed order.

Reversed intermediate functions used in instances

8 declarations
valueapReversed :: List (a -> b) -> List a -> List b
#

Apply the functions in the left list to every element in the right one, producing a list of results in reversed order.

valueexplodeReversed :: (a -> List b) -> List a -> List b
#

Use a function to produce a list of lists and then concat them sequentially, producing the results in reversed order.