[Haskell-beginners] Simple Moving Average of a list of real numbers

yi lu zhiwudazhanjiangshi at gmail.com
Tue Nov 26 01:50:58 UTC 2013


It reminds me of k-means.


On Tue, Nov 26, 2013 at 2:33 AM, Chaddaï Fouché <chaddai.fouche at gmail.com>wrote:

> On Mon, Nov 25, 2013 at 4:28 PM, Alexandr M <rus314 at gmail.com> wrote:
>
>> Hello !
>>
>> Could anybody explain me how to calculate simple moving average of a list
>> ?
>>
>> I have found several examples in internet but I completely don't
>> understand how it works.
>>
>> Basically it's necessary to iterate over the list of real numbers and
>> calculate average values over last n items in the list.
>>
>> I just can't imagine how to do it without loops.
>>
>
> Who needs loops when you have recursion, or more to the point good
> combinators ! You can do it in a few lines using only splitAt, length (to
> check the result of splitAt), zip, and scanl. (and sum, +, - and /, of
> course).
>
> Ask again, if that's not enough.
>
> --
> Jedaï
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131126/57a9fa8b/attachment.html>


More information about the Beginners mailing list