There are basically three transformations.
sortOn snd poly
poly is a list of tuples of two numbers for each polynomial term's coefficient and power. First step sorts the list of tuple by its second element which is power.groupBy ...
We group all terms by their power.groupByreturns a list of lists. Each list represent a power value.map f
For each list of lists wefoldlthe list which is basically reducing the list to a single value. For instance if we have5x^2-3x^2+x^2it evaluates to3x^2.
Once you get used to functional programming, most things will look very clear. ;)
Take a look: http://learnyouahaskell.com