I have this function that returns the second largest value from a given list:
import Data.List
secondL :: Ord a => [a] -> a
secondL xs =
let x = head xs
in let find (a, b) x = (min b (max a x), max b x)
in fst (foldl find (x, x) xs)
This function should be working correctly, but for better purity I would like to exclude the function find
's definition which is inside, and rework this function so that there is no other function declaration inside.
I was thinking about including (min b (max a x), max b x)
into foldl
argument, but this doesn't seem to be working well.