I am trying to learn Haskell and I read about tail recursions. For example I can write the sum function this way :
sum :: Num a => [a] -> a sum [] = 0 sum (x:xs) = x + summe xs But also this way
summe':: Num a => [a] -> a summe' x = iterate x 0 where iterate x y | null x = 0 + y | otherwise = iterate (tail x) (head x + y) Could someone tell me how to do it with this function? I am lost
f :: Integer -> Integer f 0 = 0 f n = n * f (n-1) + n
head,tailshould be avoided when possible, and here there is no reason to use them.