head / !! / length
Try it yourself →List access.
Syntax
head xs // xs !! i // length xs
Description
head returns the first element, xs !! i returns the i-th element (0-indexed). length returns the number of elements. Lists are printed without spaces: [1,2,3].
Example
main = do let xs = [10, 20, 30] print (head xs) print (xs !! 1) print (length xs)
Expected output
10 20 3
When to use?
Accessing data collections.