{- | Description: Penultimate element of a list Copyright: Copyright (C) 2021 Yoo Chung License: GPL-3.0-or-later Maintainer: dev@chungyc.org Some solutions to "Problems.P02" of Ninety-Nine Haskell "Problems". -} module Solutions.P02 (myButLast) where -- | Find the last but one element of a list. myButLast :: [a] -> Maybe a myButLast :: forall a. [a] -> Maybe a myButLast [a x,a _] = a -> Maybe a forall a. a -> Maybe a Just a x myButLast (a _:[a] xs) = [a] -> Maybe a forall a. [a] -> Maybe a myButLast [a] xs myButLast [a] _ = Maybe a forall a. Maybe a Nothing