• + 0 comments

    and in this essentially equates to:

    from which you can immediately write an inefficient algorithm. If you use imperative state to efficiently update the summations, you have something along the lines of what OP has written.