How does this Haskell function work? -


i struggling see how function worked. nth number should calculate sum of previous 3 elements.

f' :: integer->integer  f' = helper 0 0 1       helper b c 0 =     helper b c n = helper b c (a+b+c) (n-1) 

thanks time

say called f' 5

below sequence in executed:

iteration 1: helper 0 0 1 5

iteration 2: helper 0 1 (0+0+1) 4

iteration 3: helper 1 1 (0+1+1) 3

iteration 4: helper 1 2 (1+1+2) 2

iteration 5: helper 2 4 (1+2+4) 1

iteration 6: helper 4 7 (2+4+7) 0 => 4


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -