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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:48:16+00:00 2026-05-25T12:48:16+00:00

I have issues with the following passage from Learn You A Haskell (Great book

  • 0

I have issues with the following passage from Learn You A Haskell (Great book imo, not dissing it):

One big difference is that right
folds work on infinite lists, whereas left ones don’t! To put it
plainly, if you take an infinite list at some point and you fold it up
from the right, you’ll eventually reach the beginning of the list.
However, if you take an infinite list at a point and you try to fold
it up from the left, you’ll never reach an end!

I just don’t get this. If you take an infinite list and try to fold it up from the right then you’ll have to start at the point at infinity, which just isn’t happening (If anyone knows of a language where you can do this do tell :p). At least, you’d have to start there according to Haskell’s implementation because in Haskell foldr and foldl don’t take an argument that determines where in the list they should start folding.

I would agree with the quote iff foldr and foldl took arguments that determined where in the list they should start folding, because it makes sense that if you take an infinite list and start folding right from a defined index it will eventually terminate, whereas it doesn’t matter where you start with a left fold; you’ll be folding towards infinity. However foldr and foldl do not take this argument, and hence the quote makes no sense. In Haskell, both a left fold and a right fold over an infinite list will not terminate.

Is my understanding correct or am I missing something?

  • 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-05-25T12:48:16+00:00Added an answer on May 25, 2026 at 12:48 pm

    The key here is laziness. If the function you’re using for folding the list is strict, then neither a left fold nor a right fold will terminate, given an infinite list.

    Prelude> foldr (+) 0 [1..]
    ^CInterrupted.
    

    However, if you try folding a less strict function, you can get a terminating result.

    Prelude> foldr (\x y -> x) 0 [1..]
    1
    

    You can even get a result that is an infinite data structure, so while it does in a sense not terminate, it’s still able to produce a result that can be consumed lazily.

    Prelude> take 10 $ foldr (:) [] [1..]
    [1,2,3,4,5,6,7,8,9,10]
    

    However, this will not work with foldl, as you will never be able to evaluate the outermost function call, lazy or not.

    Prelude> foldl (flip (:)) [] [1..]
    ^CInterrupted.
    Prelude> foldl (\x y -> y) 0 [1..]
    ^CInterrupted.
    

    Note that the key difference between a left and a right fold is not the order in which the list is traversed, which is always from left to right, but rather how the resulting function applications are nested.

    • With foldr, they are nested on “the inside”

      foldr f y (x:xs) = f x (foldr f y xs)
      

      Here, the first iteration will result in the outermost application of f. Thus, f has the opportunity to be lazy so that the second argument is either not always evaluated, or it can produce some part of a data structure without forcing its second argument.

    • With foldl, they are nested on “the outside”

      foldl f y (x:xs) = foldl f (f y x) xs
      

      Here, we can’t evaluate anything until we have reached the outermost application of f, which we will never reach in the case of an infinite list, regardless of whether f is strict or not.

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

Sidebar

Related Questions

I have a few issues with the following php functions (part of a bigger
So I have the following connection string which is causing me issues. I am
I have issues understanding scopes in javascript.Let's suppose i have the following code: Ext.define('MA.controller.user',{
I have out of memory issues with following environment: Tomcat 5.1.23 Using XFire WebServices
I have some issues when sharing URLs with Twitter. I share http://google.com using following
I have issues with the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include
As described above, I have issues with @font-face not displaying in IE9 although it
I have the following list of fonts: I have no issues with using them
a other stupid question from my side ;) I have some issues with the
I've built an asp website and i have the following issues:- i'm using a

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.