haskell list element at index
To access an element at a specific index in a Haskell list, you can use the !!
operator followed by the index number. Here's an example:
myList = [1, 2, 3, 4, 5]
element = myList !! 2 -- Accessing the element at index 2 (zero-based indexing)
-- The value of `element` will be 3
In the example above, myList
is a list of integers, and element
is assigned the value at index 2 of myList
. Keep in mind that Haskell uses zero-based indexing, so the first element is at index 0, the second element is at index 1, and so on.
Please let me know if you need further assistance!