Skip to main content
edited tags
Link
Will Ness
  • 71.6k
  • 10
  • 105
  • 192
added 3 characters in body
Source Link
jazzer97
  • 157
  • 2
  • 6

I've written a simple function in haskell that is non tail recursive that sums up the values inside a list where:

nonTailRecursiveSum :: [Integer] -> Integer nonTailRecursiveSum [] = 0 --base case nonTailRecursiveSum (x:xs) = x + sum xs 

But what I'm trying to do now is to implement the same function but using tail recursion. For what i know, tail recursion performs the recursive call at the final step so i tried something like:

tailRecursiveSum :: [Integer] -> Integer tailRecursiveSum [] = 0 tailRecursiveSum (x:xs) = aux_f(x) + tailRecursivetailRecursiveSum xs . . 

But i got lost in the midway as I'm not familiar with tail recursion in Haskell. Could anyone assist me on the continuation of the tail recursive version of the code?

I've written a simple function in haskell that is non tail recursive that sums up the values inside a list where:

nonTailRecursiveSum :: [Integer] -> Integer nonTailRecursiveSum [] = 0 --base case nonTailRecursiveSum (x:xs) = x + sum xs 

But what I'm trying to do now is to implement the same function but using tail recursion. For what i know, tail recursion performs the recursive call at the final step so i tried something like:

tailRecursiveSum :: [Integer] -> Integer tailRecursiveSum [] = 0 tailRecursiveSum (x:xs) = aux_f(x) + tailRecursive xs . . 

But i got lost in the midway as I'm not familiar with tail recursion in Haskell. Could anyone assist me on the continuation of the tail recursive version of the code?

I've written a simple function in haskell that is non tail recursive that sums up the values inside a list where:

nonTailRecursiveSum :: [Integer] -> Integer nonTailRecursiveSum [] = 0 --base case nonTailRecursiveSum (x:xs) = x + sum xs 

But what I'm trying to do now is to implement the same function but using tail recursion. For what i know, tail recursion performs the recursive call at the final step so i tried something like:

tailRecursiveSum :: [Integer] -> Integer tailRecursiveSum [] = 0 tailRecursiveSum (x:xs) = aux_f(x) + tailRecursiveSum xs . . 

But i got lost in the midway as I'm not familiar with tail recursion in Haskell. Could anyone assist me on the continuation of the tail recursive version of the code?

Source Link
jazzer97
  • 157
  • 2
  • 6

Implementing tail recursion

I've written a simple function in haskell that is non tail recursive that sums up the values inside a list where:

nonTailRecursiveSum :: [Integer] -> Integer nonTailRecursiveSum [] = 0 --base case nonTailRecursiveSum (x:xs) = x + sum xs 

But what I'm trying to do now is to implement the same function but using tail recursion. For what i know, tail recursion performs the recursive call at the final step so i tried something like:

tailRecursiveSum :: [Integer] -> Integer tailRecursiveSum [] = 0 tailRecursiveSum (x:xs) = aux_f(x) + tailRecursive xs . . 

But i got lost in the midway as I'm not familiar with tail recursion in Haskell. Could anyone assist me on the continuation of the tail recursive version of the code?