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

The Archive Base Latest Questions

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

I have started learning Haskell and I have problem with understanding how cartesian product

  • 0

I have started learning Haskell and I have problem with understanding how cartesian product of lists of the list works

here is the supposed code

cprod = foldr f [[ ]]
      where f xs yss = foldr g [ ] xs
            where g x zss = foldr h zss yss
                  where h ys uss = (x : ys) : uss

What exactly I don’t get is the last function
I’ve replaced variable names as I understand it

mycart = foldr f [[]]
    where f currentresult listelem = foldr g [] currentresult
          where g currentresultonstep currentresultelem = foldr h currentresultelem listelem
                where h currentresultelemonstep onelistelem = (currentresultonstep:currentreslteleemonstep):onelistelem

Shouldn’t the last string be something like this?

where h currentresultelemonstep onelistelem = (onelistelem:currentresultelemonstep):currentresultonstep

as we try to add the elements of the list to the beginning on elements of current result
?

  • 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-15T09:48:13+00:00Added an answer on June 15, 2026 at 9:48 am

    First off, your code as written isn’t syntactically valid:

    foo.hs:3:13: parse error on input `where'
    

    Second, it seems like you’re confused about the order of arguments in the first parameter of foldr:

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

    The first argument (a) is an element of the input list ([a]), the second argument (b) is the accumulator.

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

Sidebar

Related Questions

I started learning haskell yesterday and I got stuck on a problem. After a
Just started learning Haskell. I have an empty source file with this inside: pe
I have started learning MahApps.Metro . I read the documentation and got a problem.
I have started learning Java language for Android Application developement. As per my understanding
I have started learning Haskell from Learn You a Haskell . In one of
i have started learning something about log4j as so far its working fine here
I have started learning the javascript module pattern and I have the following code:
I have started learning Objective-C, and I just wanted to verify that my understanding
I have just recently started learning Haskell and I am having a lot of
I have started learning django and have a problem with INSERT-query using ORM (DB

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.