Path To Beginnery in Functional Programming with Haskell

See the first post in this series for an introduction to this series. Quick recap: I am trying to track my path completing Haskell programming projects from books I am reading. Feel free to message me on Twitter @BarryMooreII with any corrections or suggestions on new topics.

Project 1

This is a short
problem, but I was getting stuck on a foldr implementation. I wanted to
write down the problem, reductions, correct solution, and some alternate
implementations to increase my understanding.

Definition of Problem

Implement myMaximumBy using a fold. myMaximumBy takes a comparison
function, of type (a -> a -> Ordering), and returns the greatest element of
the list based on the last value in the list which returned GT. Some
examples:

Solving The Problem

The base case, or accumulator, is simply the first value in the list. My
initial thought is that given an empty list our function should return an
error. Side note: after additional thought I decided to implement a version which
returns Maybe a, but I will show that in the Practical Considerations
section. If given a list with one element, simply return that element. Next we
need to define our folding function (for a foldr),

Wrapping Up

This wasn't a particularly difficult problem or solution, but it was one of the
first cases where my code looked correct, type-checked, and failed. It is
really important to understand the difference between foldr and foldl.
I am starting to really enjoy point-free style in Haskell. When understood, it is terse and beautiful.

Edits made on 10/18/18 cleaning up patterns with unneccesary named parameters. Replace (x:[]) with [x].