playground/haskell/99-problems/2.hs

11 lines
253 B
Haskell

-- Find second element from the end of a list
-- complete
myButLast :: [a] -> a
myButLast [] = error "List empty"
myButLast [x] = error "Single element list"
myButLast x = myButLastAux (reverse x)
myButLastAux :: [a] -> a
myButLastAux (x:xs:xss) = xs