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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:36:45+00:00 2026-06-05T07:36:45+00:00

I have a quick question about Haskell. I’ve been following Learn You a Haskell

  • 0

I have a quick question about Haskell. I’ve been following Learn You a Haskell, and am just a bit confused as to the execution order / logic of the following snippet, used to calculate the side lengths of a triangle, when all sides are equal to or less than 10 and the total perimeter of the triangle is 24:

[(a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c==24]

The part that is confusing to me is the upper expansion bound on the b and a binding. From what I gather, the ..c and ..b are used to remove additional permutations (combinations?) of the same set of triangle sides.

When I run it with the ..c/b, I get the answer:

[(6,8,10)]

When I don’t have the ..c/b:

[(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10], a^2 + b^2 == c^2, a+b+c==24]

as I didn’t when I initially typed it in, I got:

[(8,6,10),(6,8,10)]

Which is obviously representative of the same triangle, save for the a and b values have been swapped.

So, can someone walk me through the logic / execution / evaluation of what’s going on here?

  • 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-05T07:36:46+00:00Added an answer on June 5, 2026 at 7:36 am

    The original version considers all triplets (a,b,c) where c is a number between 1 and 10, b is a number between 1 and c and a is a number between 1 and b. (6,8,10) fits that criteria, (8,6,10) doesn’t (because here a is 8 and b is 6, so a isn’t between 0 and 6).

    In your version you consider all triplets (a,b,c) where a, b and c are between 1 and 10. You make no restrictions on how a, b and c relate to each other, so (8, 6, 10) is not excluded since all numbers in it are indeed between 1 and 10.

    If you think of it in terms of imperative for-loops, your version does this:

    for c from 1 to 10:
      for b from 1 to 10:
        for a from 1 to 10:
          if a^2 + b^2 == c^2 and a+b+c==24:
            add (a,b,c) to the result
    

    while the original version does this:

    for c from 1 to 10:
      for b from 1 to c:
        for c from 1 to b:
          if a^2 + b^2 == c^2 and a+b+c==24:
            add (a,b,c) to the result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just have a quick question about how to get the length of a
I have a quick question about the following expression: int a_variable = 0; if(0!=a_variable)
I just have a quick question about the conditional operator. Still a budding programmer
I just have a quick question about how to generate id's on-the-fly for HTML
I just have a quick question about IE8 Standards mode vs Quirks mode. The
A quick question about saving data in symfony 2. I have this method (just
I have a quick question about Java synchronization. Please assume the following code: public
I have a quick question about Java synchronization. Please assume the following code: public
i just have a quick question about concurrent programming in Java. for example, i
Folks, I had a quick question about Amazon EC2, I have been recently using

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.