Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:28:27+00:00 2026-06-12T09:28:27+00:00

I understand this function and the tail-recursion but I can’t figure out why the

  • 0

I understand this function and the tail-recursion but I can’t figure out why the strict evaluation is important. Without the strict evaluation it would still be tail-recursive, right? So when will this function fail without strict evaluation?

turboPower a b = turboPower' 1 a b
  where
    turboPower' x a 0 = x
    turboPower' x a b
        | x `seq` a `seq` b `seq` False = undefined
        | even b = turboPower' x (a*a) (b `div` 2)
        | otherwise = turboPower' (x*a) a (b-1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:28:28+00:00Added an answer on June 12, 2026 at 9:28 am

    It will not fail (unless the exponent is huge, so the thunks may become large enough to overflow the stack), it will (may) just be less efficient, since without the strict evaluation, the arguments become thunks, leading to

    turboPower' (let xN = let x(N-1) = ...; a(N-1) = ... in x(N-1)*a(N-1)) (let aN = let a(N-1) = ... in a(N-1)*a(n-1)) (let bN = ...)
    

    It shouldn’t be too dramatic here, since the level of nesting is logarithmic in the exponent, and thus remains small for all practical computations, but it would make a huge difference for example in

    foo :: Integer -> Integer
    foo n = go 0 n
      where
        go acc m
          | m < 1     = acc
          | otherwise = go (acc + m^3 + m `mod` 7) (m-1)
    

    where the level of nesting is linear in n.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me. I can't understand why this function, that uses texture memory __global__
This matrix transposition function works, but I'm trying to understand its step by step
I've been playing with this and I can't understand why the RegDeleteKey function is
I'm just started learning scheme and can't quite understand why this function does not
I'm trying to understand this function. What I can see is an attribute and
I don't really understand what this function is good for. Can someone explain that
There are a couple of questions about tail-recursive function e.g. this and this but
Please help me understand this recursive function... var stack = Array; function power(base, exponent){
I don't understand the last line of this function from Programming Perl 3e .
I sort of understand this, at least the function of generators (I've used them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.