Last element of list haskell

In this article let’s discuss about Last element of list haskell. Let’s go through the following methods without any delay 🙂

Method 1:

list = [1, 2, 3, 4]

last [a] -> a
last [x] 	= x
last (_:xs) = last xs

last list -- 4

Method 2 :

list = [1,2,3,4,5]
last list -- returns 5

Hope the above methods works for you. Happy Learning and get back to us Anytime.

Realted Posts : Small basic textwindow