first elem to the last list haskell code example
Example 1: last element of list haskell
list = [1, 2, 3, 4]
last [a] -> a
last [x] = x
last (_:xs) = last xs
last list -- 4
Example 2: first element in list haskell
list = [1, 2, 3]
head :: [a] -> a
head (x:_) = x
head list -- 1