[Haskell-beginners] Saving intermediate calculations

Abhinav Kalawatia kalawatia_abhinav at yahoo.com
Mon Mar 9 15:47:06 UTC 2015


  Hello,
I am facing a slight difficulty trying to do something while saving intermediate calculations

week    actual_ sales(a)     forecast(f)                        forecast(f)                              forecast(f)
 1            20                          f1 = a1                              f1 = 20                                    f1 = 20
 2            27                          f2 = f1 + 0.5*(a1 - f1)        f2 = 20 +0.5(20-20)                f2 = 20
 3            25                          f3 = f2 +  0.5*(a2-f2)         f3 = 20+0.5*(27-20)               f3=23.5
 4            22 


When I execute a function to achieve this in Haskell, I get the forecast for the fourth period. Can I save the values for intermediate period(1..3) also?


Please find my Haskell code below:
a = 0.5
ipt = [20,27,25,22]
avg :: [Double] -> Double
avg (x:xs) = (a*x) + (1-a)*(avg xs)
avg [] = 0
Could you please help me with this, thanking you in anticipation

Regards,Abhinav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150309/1524dd95/attachment.html>


More information about the Beginners mailing list