Have you ever wanted to get all the elements of a list except the first element? In this shot, you will learn how to get all elements of a list excluding the first one.
A list in Haskell can be anything ranging from strings, an array of numbers, etc,.
Remember a list can also be a string of characters so, in situations where you just want the last letters of a word without the first letter, that’s where the tail method will help.
List enables you to manipulate arrays and strings. Look up my shot on how to get element of list at index. In that shot, I discuss how to get any element from a list with index. For examples, if you want to get the 3rd letter in the word ‘great’ you will be able to do that with help of a list.
The tail of a list is everything in the list except the first element of the list. The tail of a list in Haskell is different from the last element of a list.
tail list
: you call the tail before the list.The tail
receives one parameter which is the list of element.
main = dolet list = [2,3,4,5,6]print(tail list)
From the example above we use the tail method to get the tail
elements of our list. Notice how from the beginning the list had 5 element but when we print it with the tail
method, it returned all the elements of the list except the first element.