:: [a] -> [a] -> [a]

(++) appends two lists, i.e.,
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
[x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
If the first list is not finite, the result is the first list.

Performance considerations

This function takes linear time in the number of elements of the first list. Thus it is better to associate repeated applications of (++) to the right (which is the default behaviour): xs ++ (ys ++ zs) or simply xs ++ ys ++ zs, but not (xs ++ ys) ++ zs. For the same reason concat = foldr (++) [] has linear performance, while foldl (++) [] is prone to quadratic slowdown

Examples

>>> [1, 2, 3] ++ [4, 5, 6]
[1,2,3,4,5,6]
>>> [] ++ [1, 2, 3]
[1,2,3]
>>> [3, 2, 1] ++ []
[3,2,1]
An associative operation. The default definition is
mplus = (<|>)
An associative binary operation
See recover.
Catch and handle an exception of type Interrupt. See withInterrupt for more explanation.
handleInterrupt (outputStrLn "Ctrl+C was pressed, aborting!") someLongAction
Sequence actions, discarding the value of the first argument.

Examples

If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing.
>>> Just 2 *> Just 3
Just 3
>>> Nothing *> Just 3
Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>> import Data.Char

>>> import GHC.Internal.Text.ParserCombinators.ReadP

>>> let p = string "my name is " *> munch1 isAlpha <* eof

>>> readP_to_S p "my name is Simon"
[("Simon","")]
Sequence actions, discarding the value of the second argument.
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages. 'as >> bs' can be understood as the do expression
do as
bs
or in terms of (>>=) as
as >>= const bs
Run an action only if an exception is thrown in the main action. The exception is not caught, simply rethrown. NOTE The action is only run if an exception is thrown. If the monad supports other ways of aborting the computation, the action won't run if those other kinds of errors are thrown. See onError.
Run an action only if an error is thrown in the main action. Unlike onException, this works with every kind of error, not just exceptions. For example, if f is an ExceptT computation which aborts with a Left, the computation onError f g will execute g, while onException f g will not. This distinction is only meaningful for monads which have multiple exit points, such as Except and MaybeT. For monads that only have a single exit point, there is no difference between onException and onError, except that onError has a more constrained type.
Perform an action with a finalizer action that is run, even if an error occurs.
The \\ function is list difference (non-associative). In the result of xs \\ ys, the first occurrence of each element of ys in turn (if any) has been removed from xs. Thus (xs ++ ys) \\ xs == ys. It is a special case of deleteFirstsBy, which allows the programmer to supply their own equality test.

Examples

>>> "Hello World!" \\ "ell W"
"Hoorld!"
The second list must be finite, but the first may be infinite.
>>> take 5 ([0..] \\ [2..4])
[0,1,5,6,7]
>>> take 5 ([0..] \\ [2..])
* Hangs forever *
The union function returns the list union of the two lists. It is a special case of unionBy, which allows the programmer to supply their own equality test.

Examples

>>> "dog" `union` "cow"
"dogcw"
If equal elements are present in both lists, an element from the first list will be used. If the second list contains equal elements, only the first one will be retained:
>>> import Data.Semigroup(Arg(..))

>>> union [Arg () "dog"] [Arg () "cow"]
[Arg () "dog"]

>>> union [] [Arg () "dog", Arg () "cow"]
[Arg () "dog"]
However if the first list contains duplicates, so will the result:
>>> "coot" `union` "duck"
"cootduk"

>>> "duck" `union` "coot"
"duckot"
union is productive even if both arguments are infinite.
>>> [0, 2 ..] `union` [1, 3 ..]
[0,2,4,6,8,10,12..
The intersect function takes the list intersection of two lists. It is a special case of intersectBy, which allows the programmer to supply their own equality test.
Examples
>>> [1,2,3,4] `intersect` [2,4,6,8]
[2,4]
If equal elements are present in both lists, an element from the first list will be used, and all duplicates from the second list quashed:
>>> import Data.Semigroup

>>> intersect [Arg () "dog"] [Arg () "cow", Arg () "cat"]
[Arg () "dog"]
However if the first list contains duplicates, so will the result.
>>> "coot" `intersect` "heron"
"oo"

>>> "heron" `intersect` "coot"
"o"
If the second list is infinite, intersect either hangs or returns its first argument in full. Otherwise if the first list is infinite, intersect might be productive:
>>> intersect [100..] [0..]
[100,101,102,103...

>>> intersect [0] [1..]
* Hangs forever *

>>> intersect [1..] [0]
* Hangs forever *

>>> intersect (cycle [1..3]) [2]
[2,2,2,2...
Like "Data.List.union", but has O(n log n) complexity instead of O(n^2).