| Copyright | (c) The University of Glasgow 1994-2002 |
|---|---|
| License | see libraries/base/LICENSE |
| Maintainer | cvs-ghc@haskell.org |
| Stability | internal |
| Portability | non-portable (GHC Extensions) |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
GHC.List
Description
The List data type and its operations
map :: (a -> b) -> [a] -> [b]Source#
mapf xs is the list obtained by applyingf to each element ofxs, i.e.,
map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]map f [x1, x2, ...] == [f x1, f x2, ...]
(++) :: [a] -> [a] -> [a]infixr 5Source#
Append 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.
filter :: (a ->Bool) -> [a] -> [a]Source#
filter, applied to a predicate and a list, returns the list of those elements that satisfy the predicate; i.e.,
filter p xs = [ x | x <- xs, p x]
Return all the elements of a list except the last one. The list must be non-empty.
O(n).length returns the length of a finite list as anInt. It is an instance of the more generalgenericLength, the result type of which may be any kind of number.
(!!) :: [a] ->Int -> ainfixl 9Source#
List index (subscript) operator, starting from 0. It is an instance of the more generalgenericIndex, which takes an index of any integral type.
foldl ::forall a b. (b -> a -> b) -> b -> [a] -> bSource#
foldl, applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:
foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
The list must be finite.
foldr :: (a -> b -> b) -> b -> [a] -> bSource#
foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a list, reduces the list using the binary operator, from right to left:
foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
iterate' :: (a -> a) -> a -> [a]Source#
'iterate\'' is the strict version ofiterate.
It ensures that the result of each application of force to weak head normal form before proceeding.
replicate ::Int -> a -> [a]Source#
replicaten x is a list of lengthn withx the value of every element. It is an instance of the more generalgenericReplicate, in whichn may be of any integral type.
cycle ties a finite list into a circular one, or equivalently, the infinite repetition of the original list. It is the identity on infinite lists.
take ::Int -> [a] -> [a]Source#
taken, applied to a listxs, returns the prefix ofxs of lengthn, orxs itself ifn >:length xs
take 5 "Hello World!" == "Hello"take 3 [1,2,3,4,5] == [1,2,3]take 3 [1,2] == [1,2]take 3 [] == []take (-1) [1,2] == []take 0 [1,2] == []
It is an instance of the more generalgenericTake, in whichn may be of any integral type.
drop ::Int -> [a] -> [a]Source#
dropn xs returns the suffix ofxs after the firstn elements, or[] ifn >:length xs
drop 6 "Hello World!" == "World!"drop 3 [1,2,3,4,5] == [4,5]drop 3 [1,2] == []drop 3 [] == []drop (-1) [1,2] == [1,2]drop 0 [1,2] == [1,2]
It is an instance of the more generalgenericDrop, in whichn may be of any integral type.
product ::Num a => [a] -> aSource#
Theproduct function computes the product of a finite list of numbers.
splitAt ::Int -> [a] -> ([a], [a])Source#
splitAtn xs returns a tuple where first element isxs prefix of lengthn and second element is the remainder of the list:
splitAt 6 "Hello World!" == ("Hello ","World!")splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])splitAt 1 [1,2,3] == ([1],[2,3])splitAt 3 [1,2,3] == ([1,2,3],[])splitAt 4 [1,2,3] == ([1,2,3],[])splitAt 0 [1,2,3] == ([],[1,2,3])splitAt (-1) [1,2,3] == ([],[1,2,3])It is equivalent to( whentake n xs,drop n xs)n is not_|_ (splitAt _|_ xs = _|_).splitAt is an instance of the more generalgenericSplitAt, in whichn may be of any integral type.
takeWhile :: (a ->Bool) -> [a] -> [a]Source#
takeWhile, applied to a predicatep and a listxs, returns the longest prefix (possibly empty) ofxs of elements that satisfyp:
takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2]takeWhile (< 9) [1,2,3] == [1,2,3]takeWhile (< 0) [1,2,3] == []
span :: (a ->Bool) -> [a] -> ([a], [a])Source#
span, applied to a predicatep and a listxs, returns a tuple where first element is longest prefix (possibly empty) ofxs of elements that satisfyp and second element is the remainder of the list:
span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4])span (< 9) [1,2,3] == ([1,2,3],[])span (< 0) [1,2,3] == ([],[1,2,3])
break :: (a ->Bool) -> [a] -> ([a], [a])Source#
break, applied to a predicatep and a listxs, returns a tuple where first element is longest prefix (possibly empty) ofxs of elements thatdo not satisfyp and second element is the remainder of the list:
break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4])break (< 9) [1,2,3] == ([],[1,2,3])break (> 9) [1,2,3] == ([1,2,3],[])
lookup ::Eq a => a -> [(a, b)] ->Maybe bSource#
lookupkey assocs looks up a key in an association list.
unzip :: [(a, b)] -> ([a], [b])Source#
unzip transforms a list of pairs into a list of first components and a list of second components.
errorEmptyList ::String -> aSource#
Produced byHaddock version 2.20.0