last element of list haskell

Last Element of a List in Haskell

To get the last element of a list in Haskell, you can use the last function. The last function takes a list as input and returns the last element of that list.

Here's an example:

myList = [1, 2, 3, 4, 5]
lastElement = last myList

In this example, lastElement will be assigned the value 5, which is the last element of the list myList.

Please note that the last function will throw an error if you pass an empty list as input. So, make sure to handle empty lists appropriately in your code.

I hope this helps!