The last
method gets the last element of a Haskel list.
A Haskell list can be of any data type, a string of letters, an array of numbers, etc.
Getting the last element of a list can come in handy while working with arrays. Like in functions where we add into an array or remove from it, we will want to know the last element in the array after the action.
last list
The last
method takes the list
as a parameter.
Let’s look at the executable code below to see how we can get the last element:
main = dolet x = [1,3,5,7,9]print(last x)
x
and assign an array of numbers to it.print()
method. Here, we pass the last()
function with the list as an argument.