Eq package:relude

The value of seq a b is bottom if a is bottom, and otherwise equal to b. In other words, it evaluates the first argument a to weak head normal form (WHNF). seq is usually introduced to improve performance by avoiding unneeded laziness. A note on evaluation order: the expression seq a b does not guarantee that a will be evaluated before b. The only guarantee given by seq is that the both a and b will be evaluated before seq returns a value. In particular, this means that b may be evaluated before a. If you need to guarantee a specific order of evaluation, you must use the function pseq from the "parallel" package.
General-purpose finite sequences.
This module contains useful functions to evaluate expressions to weak-head normal form (WHNF) or just normal form (NF). Useful to force traces or errors inside monadic computations or to remove space leaks.
deepseq: fully evaluates the first argument, before returning the second. The name deepseq is used to illustrate the relationship to seq: where seq is shallow in the sense that it only evaluates the top level of its argument, deepseq traverses the entire data structure evaluating it completely. deepseq can be useful for forcing pending exceptions, eradicating space leaks, or forcing lazy I/O to happen. It is also useful in conjunction with parallel Strategies (see the parallel package). There is no guarantee about the ordering of evaluation. The implementation may evaluate the components of the structure in any order or in parallel. To impose an actual order on evaluation, use pseq from Control.Parallel in the parallel package.
Sequences all the actions in a structure, building a new structure with the same shape using the results of the actions. For a version that ignores the results, see bisequence_.
bisequencebitraverse id id

Examples

Basic usage:
>>> bisequence (Just 4, Nothing)
Nothing
>>> bisequence (Just 4, Just 5)
Just (4,5)
>>> bisequence ([1, 2, 3], [4, 5])
[(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
Evaluate each action in the structure from left to right, and ignore the results. For a version that doesn't ignore the results, see bisequence.

Examples

Basic usage:
>>> bisequence_ (print "Hello", print "World")
"Hello"
"World"
>>> bisequence_ (Left (print "Hello"))
"Hello"
>>> bisequence_ (Right (print "World"))
"World"
Evaluate each monadic action in the structure from left to right, and collect the results. For a version that ignores the results see sequence_.

Examples

Basic usage: The first two examples are instances where the input and and output of sequence are isomorphic.
>>> sequence $ Right [1,2,3,4]
[Right 1,Right 2,Right 3,Right 4]
>>> sequence $ [Right 1,Right 2,Right 3,Right 4]
Right [1,2,3,4]
The following examples demonstrate short circuit behavior for sequence.
>>> sequence $ Left [1,2,3,4]
Left [1,2,3,4]
>>> sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
Left 0
Evaluate each action in the structure from left to right, and collect the results. For a version that ignores the results see sequenceA_.

Examples

Basic usage: For the first two examples we show sequenceA fully evaluating a a structure and collecting the results.
>>> sequenceA [Just 1, Just 2, Just 3]
Just [1,2,3]
>>> sequenceA [Right 1, Right 2, Right 3]
Right [1,2,3]
The next two example show Nothing and Just will short circuit the resulting structure if present in the input. For more context, check the Traversable instances for Either and Maybe.
>>> sequenceA [Just 1, Just 2, Just 3, Nothing]
Nothing
>>> sequenceA [Right 1, Right 2, Right 3, Left 4]
Left 4
Evaluate each action in the structure from left to right, and ignore the results. For a version that doesn't ignore the results see sequenceA. sequenceA_ is just like sequence_, but generalised to Applicative actions.

Examples

Basic usage:
>>> sequenceA_ [print "Hello", print "world", print "!"]
"Hello"
"world"
"!"
Evaluate each monadic action in the structure from left to right, and ignore the results. For a version that doesn't ignore the results see sequence. sequence_ is just like sequenceA_, but specialised to monadic actions.
The subsequences function returns the list of all subsequences of the argument.

Laziness

subsequences does not look ahead unless it must:
>>> take 1 (subsequences undefined)
[[]]

>>> take 2 (subsequences ('a' : undefined))
["","a"]

Examples

>>> subsequences "abc"
["","a","b","ab","c","ac","bc","abc"]
This function is productive on infinite inputs:
>>> take 8 $ subsequences ['a'..]
["","a","b","ab","c","ac","bc","abc"]