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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:29:26+00:00 2026-05-29T11:29:26+00:00

Reading Real World Haskell, on page 95 the author provides an example: myFoldl f

  • 0

Reading “Real World Haskell”, on page 95 the author provides an example:

myFoldl f z xs = foldr step id xs z
    where step x g a = g (f a x)

My question is: Why does this code compile? foldr takes only three arguments – but here, it is passed four: step, id, xs, z.

For example, this doesn’t work (because sum expects one):

sum filter odd [1,2,3]

instead I must write:

sum $ filter odd [1,2,3]
  • 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-29T11:29:27+00:00Added an answer on May 29, 2026 at 11:29 am

    Here’s the type of foldr:

    Prelude> :t foldr
    foldr :: (a -> b -> b) -> b -> [a] -> b
    

    Can we figure out how it becomes a four-argument function? Let’s give it a try!

    1. we’re giving it id :: d -> d as the second parameter (b), so let’s substitute that into the type:

      (a -> (d -> d) -> (d -> d)) -> (d -> d) -> [a] -> (d -> d)
      
    2. in Haskell, a -> a -> a is the same as a -> (a -> a), which gives us (removing the last set of parentheses):

      (a -> (d -> d) -> (d -> d)) -> (d -> d) -> [a] -> d -> d
      
    3. let’s simplify, by substituting e for (a -> (d -> d) -> (d -> d)) and f for (d -> d), to make it easier to read:

      e -> f -> [a] -> d -> d
      

    So we can plainly see that we’ve constructed a four-argument function! My head hurts.


    Here’s a simpler example of creating an n + 1-argument function from an n-arg func:

    Prelude> :t id
    id :: a -> a
    

    id is a function of one argument.

    Prelude> id id id id id 5
    5
    

    But I just gave it 5 args!

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

Sidebar

Related Questions

Reading Real world Haskell i found some intresting question about data types: This pattern
While reading Real world Haskell I came up with this note: ghci> :info (+)
I'm reading the Monads chapter in Real World Haskell (chapter 14). A function is
I have been reading Real World Haskell , and I am nearing the end,
I am reading the real world haskell Chapter 9. There is a maybeIO function
I am new to Haskell and I am reading the book Real World Haskell
Firstly, Real World Haskell , which I am reading, says to never use foldl
I'm following a tutorial. (Real World Haskell) And I have one beginner question about
Reading the Scala by Example book and there is this example when Martin explains
I'm reading the book Real-world functional programming by Tomas Petricek and Jon Skeet and

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.