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 8799851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:25:59+00:00 2026-06-14T00:25:59+00:00

Is difference between foldl and foldr just the direction of looping? I thought there

  • 0

Is difference between foldl and foldr just the direction of looping? I thought there was a difference in what they did, not just in the direction?

  • 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-14T00:26:00+00:00Added an answer on June 14, 2026 at 12:26 am

    There’s a difference if your function isn’t associative (i.e. it matters which way you bracket expressions) so for example,
    foldr (-) 0 [1..10] = -5 but foldl (-) 0 [1..10] = -55.
    This is because the former is equal to 1-(2-(3-(4-(5-(6-(7-(8-(9-(10 - 0))))))))), whereas the latter is (((((((((0-1)-2)-3)-4)-5)-6)-7)-8)-9)-10.

    Whereas because (+) is associative (doesn’t matter what order you add subexpressions),
    foldr (+) 0 [1..10] = 55 and foldl (+) 0 [1..10] = 55. (++) is another associative operation because xs ++ (ys ++ zs) gives the same answer as (xs ++ ys) ++ zs (although the first one is faster – don’t use foldl (++)).

    Some functions only work one way:
    foldr (:) :: [a] -> [a] -> [a] but foldl (:) is nonsense.

    Have a look at Cale Gibbard’s diagrams (from the wikipedia article); you can see f getting called with genuinely different pairs of data:
    foldrfoldl

    Another difference is that because it matches the structure of the list, foldr is often more efficient for lazy evaluation, so can be used with an infinite list as long as f is non-strict in its second argument (like (:) or (++)). foldl is only rarely the better choice. If you’re using foldl it’s usually worth using foldl' because it’s strict and stops you building up a long list of intermediate results. (More on this topic in the answers to this question.)

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

Sidebar

Related Questions

Is there a difference between this.form and document.forms (document[forms]) or, are they similar? Here
JAVA : is there a difference between the two references p && pp? PrintStream
Is there any tangible difference between the two forms of syntax available for creating
Is there any difference between ReferencePath with condition '%(CopyLocal)'=='true' and ReferenceCopyLocalPaths ? The question
I'm not sure what the difference between these two pieces of code is (with
The difference between a JavaScript Array , and Object is not very big. In
Is there any difference between: <img src=http://www.foo.com/bar.jpg /> and <img src=/bar.jpg /> ? Is
Are there any practical difference between the two coding patterns in Delphi: Version 1
Is there any difference between these two methods for deleting elements in Matlab: ElementsToDelete
I am not sure what is the difference between fold and foldLeft in Scala.

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.