What is the fastest way to get the last element of a list in Haskell. Also in next iteration, I want to remove first and last element of the list. What is the most elegant way to do it? I am trying list comprehension, but that does not look very efficient!
You can use the last
function to get the last element of a list.
As for how to remove the first and last elements, you could use (init . tail)
, but I don't know how efficient that is.
I think this image from Learn You A Haskell shows the list functions fairly well: