-
Header:
head, last :: [a] -> a
-
Description:
head xs
is the first element of thexs
list.last xs
is the last element of thexs
list.
Error if
xs
is empty. -
Examples:
head [1 .. 4] π 1 last [1 .. 4] π 4
-
Header:
tail, init :: [a] -> [a]
-
Description:
tail xs
is thexs
list without its first element.init xs
is thexs
list without its last element.
Error if
xs
is empty. -
Examples:
tail [1..4] π [2, 3, 4] init [1..4] π [1, 2, 3]
-
Header:
reverse :: [a] -> [a]
-
Description:
reverse xs
is thexs
list in the reverse order. -
Examples:
reverse [1..4] π [4, 3, 2, 1]
-
Header:
length :: [a] -> Int
-
Description:
length xs
is the number of elements elements in thexs
list.
-
Header:
null :: [a] -> Bool
-
Description:
null xs
tells whether thexs
list is empty.
-
Header:
elem :: (Eq a) => a -> [a] -> Bool
-
Description:
elem x xs
tells whetherx
is contained in thexs
list.
-
Header:
(!!) :: [a] -> Int -> a
-
Description:
xs !! is the
i-th element of the
xs` list (starting from zero).
-
Header:
maximum, minimum :: (Ord a) => [a] -> a
-
Description:
maximum xs
is the bigger element from thexs
list (not empty!).minimum xs
is the smaller element from thexs
list (not empty!).
-
Header:
and, or :: [Bool] -> Bool
-
Description:
and bs
is the conjuntion of thebs
list of bolleans.or bs
is the disjuntion of thebs
list of bolleans.
-
Header:
sum, prod :: [Int] -> Int
-
Description:
sum xs
is the sum of the elements in thexs
list.prod xs
is the product of the elements in thexs
list.
-
Examples:
fact n = prod [1 .. n] fact 5 π 120
-
Header:
take, drop :: Int -> [a] -> [a]
-
Description:
take n xs
is the prefix of lengthn
of thexs
list.drop n xs
is the sufix of thexs
list when the firstn
elements are removed.
-
Examples:
take 3 [1 .. 7] π [1, 2, 3] drop 3 [1 .. 7] π [4, 5, 6, 7]
-
Header:
zip :: [a] -> [b] -> [(a, b)]
-
Description:
zip xs ys
is the list that joins, in ordee, each pair of elements fromxs
andys
. If some list lacks elements, the result is truncated. -
Examples:
zip [1, 2, 3] ['a', 'b', 'c'] π [(1, 'a'), (2, 'b'), (3, 'c')] zip [1 .. 10] [1 .. 3] π [(1, 1), (2, 2), (3, 3)]
-
Header:
repeat :: a -> [a]
-
Description:
repeat x
is the infinite list whose element are alwaysx
. -
Examples:
repeat 3 π [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ...] take 4 (repeat 3) π [3, 3, 3, 3]
-
Header:
concat :: [[a]] -> [a]
-
Description:
concat xs
is the list that concatenates all lists inxs
. -
Examples:
concat [[1, 2, 3], [], [3], [1, 2]] π [1, 2, 3, 3, 1, 2]