Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
14 lines (10 sloc) 286 Bytes
lastButOne :: [a] -> a
lastButOne [] = undefined
lastButOne [x] = undefined
lastButOne [x, y] = x
lastButOne (x:xs) = lastButOne xs
lastButOne' :: [a] -> a
lastButOne' = head . tail . reverse
main = do
print $ lastButOne "abcd"
print $ lastButOne' "abcd"