-
Header:
head, last :: [a] -> a
-
Description:
head xsis the first element of thexslist.last xsis the last element of thexslist.
Error if
xsis empty. -
Examples:
head [1 .. 4] π 1 last [1 .. 4] π 4
-
Header:
tail, init :: [a] -> [a]
-
Description:
tail xsis thexslist without its first element.init xsis thexslist without its last element.
Error if
xsis empty. -
Examples:
tail [1..4] π [2, 3, 4] init [1..4] π [1, 2, 3]
-
Header:
reverse :: [a] -> [a]
-
Description:
reverse xsis thexslist in the reverse order. -
Examples:
reverse [1..4] π [4, 3, 2, 1]
-
Header:
length :: [a] -> Int
-
Description:
length xsis the number of elements elements in thexslist.
-
Header:
null :: [a] -> Bool
-
Description:
null xstells whether thexslist is empty.
-
Header:
elem :: (Eq a) => a -> [a] -> Bool
-
Description:
elem x xstells whetherxis contained in thexslist.
-
Header:
(!!) :: [a] -> Int -> a
-
Description:
xs !! is thei-th element of thexs` list (starting from zero).
-
Header:
maximum, minimum :: (Ord a) => [a] -> a
-
Description:
maximum xsis the bigger element from thexslist (not empty!).minimum xsis the smaller element from thexslist (not empty!).
-
Header:
and, or :: [Bool] -> Bool
-
Description:
and bsis the conjuntion of thebslist of bolleans.or bsis the disjuntion of thebslist of bolleans.
-
Header:
sum, prod :: [Int] -> Int
-
Description:
sum xsis the sum of the elements in thexslist.prod xsis the product of the elements in thexslist.
-
Examples:
fact n = prod [1 .. n] fact 5 π 120
-
Header:
take, drop :: Int -> [a] -> [a]
-
Description:
take n xsis the prefix of lengthnof thexslist.drop n xsis the sufix of thexslist when the firstnelements 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 ysis the list that joins, in ordee, each pair of elements fromxsandys. 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 xis 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 xsis the list that concatenates all lists inxs. -
Examples:
concat [[1, 2, 3], [], [3], [1, 2]] π [1, 2, 3, 3, 1, 2]