Movatterモバイル変換


[0]ホーム

URL:


base-4.12.0.0: Basic libraries

Copyright(c) The University of Glasgow 1994-2002
Licensesee libraries/base/LICENSE
Maintainercvs-ghc@haskell.org
Stabilityinternal
Portabilitynon-portable (GHC Extensions)
Safe HaskellTrustworthy
LanguageHaskell2010

GHC.List

Description

The List data type and its operations

Synopsis

Documentation

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]

concat :: [[a]] -> [a]Source#

Concatenate a list of lists.

head :: [a] -> aSource#

Extract the first element of a list, which must be non-empty.

last :: [a] -> aSource#

Extract the last element of a list, which must be finite and non-empty.

tail :: [a] -> [a]Source#

Extract the elements after the head of a list, which must be non-empty.

init :: [a] -> [a]Source#

Return all the elements of a list except the last one. The list must be non-empty.

uncons :: [a] ->Maybe (a, [a])Source#

Decompose a list into its head and tail. If the list is empty, returnsNothing. If the list is non-empty, returnsJust (x, xs), wherex is the head of the list andxs its tail.

Since: 4.8.0.0

null :: [a] ->BoolSource#

Test whether a list is empty.

length :: [a] ->IntSource#

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.

foldl' ::forall a b. (b -> a -> b) -> b -> [a] -> bSource#

A strict version offoldl.

foldl1 :: (a -> a -> a) -> [a] -> aSource#

foldl1 is a variant offoldl that has no starting value argument, and thus must be applied to non-empty lists.

foldl1' :: (a -> a -> a) -> [a] -> aSource#

A strict version offoldl1

scanl :: (b -> a -> b) -> b -> [a] -> [b]Source#

scanl is similar tofoldl, but returns a list of successive reduced values from the left:

scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]

Note that

last (scanl f z xs) == foldl f z xs.

scanl1 :: (a -> a -> a) -> [a] -> [a]Source#

scanl1 is a variant ofscanl that has no starting value argument:

scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]

scanl' :: (b -> a -> b) -> b -> [a] -> [b]Source#

A strictly accumulating version ofscanl

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)...)

foldr1 :: (a -> a -> a) -> [a] -> aSource#

foldr1 is a variant offoldr that has no starting value argument, and thus must be applied to non-empty lists.

scanr :: (a -> b -> b) -> b -> [a] -> [b]Source#

scanr is the right-to-left dual ofscanl. Note that

head (scanr f z xs) == foldr f z xs.

scanr1 :: (a -> a -> a) -> [a] -> [a]Source#

scanr1 is a variant ofscanr that has no starting value argument.

iterate :: (a -> a) -> a -> [a]Source#

iteratef x returns an infinite list of repeated applications off tox:

iterate f x == [x, f x, f (f x), ...]

Note thatiterate is lazy, potentially leading to thunk build-up if the consumer doesn't force each iterate. See 'iterate\'' for a strict variant of this function.

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.

repeat :: a -> [a]Source#

repeatx is an infinite list, withx the value of every element.

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 :: [a] -> [a]Source#

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.

sum ::Num a => [a] -> aSource#

Thesum function computes the sum of a finite list of numbers.

product ::Num a => [a] -> aSource#

Theproduct function computes the product of a finite list of numbers.

maximum ::Ord a => [a] -> aSource#

maximum returns the maximum value from a list, which must be non-empty, finite, and of an ordered type. It is a special case ofmaximumBy, which allows the programmer to supply their own comparison function.

minimum ::Ord a => [a] -> aSource#

minimum returns the minimum value from a list, which must be non-empty, finite, and of an ordered type. It is a special case ofminimumBy, which allows the programmer to supply their own comparison function.

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(take n xs,drop n xs) whenn 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] == []

dropWhile :: (a ->Bool) -> [a] -> [a]Source#

dropWhilep xs returns the suffix remaining aftertakeWhilep xs:

dropWhile (< 3) [1,2,3,4,5,1,2,3] == [3,4,5,1,2,3]dropWhile (< 9) [1,2,3] == []dropWhile (< 0) [1,2,3] == [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])

spanp xs is equivalent to(takeWhile p xs,dropWhile p xs)

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],[])

breakp is equivalent tospan (not . p).

reverse :: [a] -> [a]Source#

reversexs returns the elements ofxs in reverse order.xs must be finite.

and :: [Bool] ->BoolSource#

and returns the conjunction of a Boolean list. For the result to beTrue, the list must be finite;False, however, results from aFalse value at a finite index of a finite or infinite list.

or :: [Bool] ->BoolSource#

or returns the disjunction of a Boolean list. For the result to beFalse, the list must be finite;True, however, results from aTrue value at a finite index of a finite or infinite list.

any :: (a ->Bool) -> [a] ->BoolSource#

Applied to a predicate and a list,any determines if any element of the list satisfies the predicate. For the result to beFalse, the list must be finite;True, however, results from aTrue value for the predicate applied to an element at a finite index of a finite or infinite list.

all :: (a ->Bool) -> [a] ->BoolSource#

Applied to a predicate and a list,all determines if all elements of the list satisfy the predicate. For the result to beTrue, the list must be finite;False, however, results from aFalse value for the predicate applied to an element at a finite index of a finite or infinite list.

elem ::Eq a => a -> [a] ->Boolinfix 4Source#

elem is the list membership predicate, usually written in infix form, e.g.,x `elem` xs. For the result to beFalse, the list must be finite;True, however, results from an element equal tox found at a finite index of a finite or infinite list.

notElem ::Eq a => a -> [a] ->Boolinfix 4Source#

notElem is the negation ofelem.

lookup ::Eq a => a -> [(a, b)] ->Maybe bSource#

lookupkey assocs looks up a key in an association list.

concatMap :: (a -> [b]) -> [a] -> [b]Source#

Map a function over a list and concatenate the results.

zip :: [a] -> [b] -> [(a, b)]Source#

zip takes two lists and returns a list of corresponding pairs.

zip [1, 2] ['a', 'b'] = [(1, 'a'), (2, 'b')]

If one input list is short, excess elements of the longer list are discarded:

zip [1] ['a', 'b'] = [(1, 'a')]zip [1, 2] ['a'] = [(1, 'a')]

zip is right-lazy:

zip [] _|_ = []zip _|_ [] = _|_

zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]Source#

zip3 takes three lists and returns a list of triples, analogous tozip.

zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]Source#

zipWith generaliseszip by zipping with the function given as the first argument, instead of a tupling function. For example,zipWith (+) is applied to two lists to produce the list of corresponding sums.

zipWith is right-lazy:

zipWith f [] _|_ = []

zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]Source#

ThezipWith3 function takes a function which combines three elements, as well as three lists and returns a list of their point-wise combination, analogous tozipWith.

unzip :: [(a, b)] -> ([a], [b])Source#

unzip transforms a list of pairs into a list of first components and a list of second components.

unzip3 :: [(a, b, c)] -> ([a], [b], [c])Source#

Theunzip3 function takes a list of triples and returns three lists, analogous tounzip.

errorEmptyList ::String -> aSource#

Produced byHaddock version 2.20.0


[8]ページ先頭

©2009-2025 Movatter.jp