Writing compact code with HOF
Thanks to their function parameters, the behavior of HOF can be customized more extensively than that of similar first-order functions. This means they can be used in more circumstances. That is particularly true for the HOF of the previous sections because they cover highly general code patterns. In this section, we will show how some problems can be quickly and compactly solved by combining a number of HOF.
Standard deviation
The standard deviation of a list of numbers is a well-known statistical value that characterizes the amount of variation among those numbers. It is defined in terms of the average of those numbers. Let us first work out how to implement this average and then move on to the actual standard deviation.
Average
This average can easily be computed using predefined first-order functions:
average :: [Float] -> Float average l = sum l / fromIntegral (length l)
Both sum and length are predefined functions that are themselves...