Finding Local Maxima The following function finds all local maxima.

A local maxima is an element of a list such that it's greater than either of its neighbor elements. An element with 1 neighbor is not a local maximum.

localMaxima :: [Integer] -&gt; [Integer]
localMaxima (x:y:z:zs) = if (y &gt; x &amp;&amp; y &gt; z) then y : localMaxima (y:z:zs) 
                         else localMaxima (y:z:zs)
localMaxima _          = []


Please critique it.

Examples:

ghci&gt; localMaxima [1,3,2,55,2] 
[3,55]
ghci&gt; localMaxima [1,3,2,55,1000000000]
[3]
You have redundant parentheses here: (y &gt; x &amp;&amp; y &gt; z). You can also make your type more generic: localMaxima :: Ord a =&gt; [a] -&gt; [a].

I think it looks a bit cleaner using an as-pattern and guard clauses. This way you don't need zs and can just write _.

localMaxima (x:rest@(y:z:_))
  | y &gt; x &amp;&amp; y &gt; z = y : localMaxima rest
  | otherwise      = localMaxima rest
localMaxima _ = []


In fact, if you know that y &gt; z then you don't need to check if z is a local maximum.