I have a function that is supposed to return the 2nd last element of a list. Function will return Nothing if nothing can be returned.
data Maybe a = Nothing | Just a
secondLast :: [a] -> Maybe a
secondLast [] = Nothing
secondLast [a, _] = a
secondLast (_:xs) = secondLast xs
However on compiling i receive this error
* Occurs check: cannot construct the infinite type: a ~ Maybe a
* In the expression: a
In an equation for `secondLast': secondLast [a, _] = a
* Relevant bindings include
a :: a (bound at <interactive>:92:13)
secondLast :: [a] -> Maybe a (bound at <interactive>:92:1)
What am i doing wrong here?