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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:48:31+00:00 2026-05-29T08:48:31+00:00

the task ist to translate this f = do c <- [1 .. 200]

  • 0

the task ist to translate this

f = do
    c <- [1 .. 200]
    b <- [1 .. 200]
    guard (c >= b)
    a <- [1 .. 200]
    guard (a >= b && (c^2 - a^2 == b^2))
    return (a,b, c)

into a non-sugar verion.

I think I got most of it figured out, but I’m stuck in the middle with a problem I need to fix before I can continue. So far I have:

f = [1 .. 200] >>= \c ->
    [1 .. 200] >>= \b ->
    if (c >= b) 
        then [1 .. 200] >>= \a -> if (a >= b && (c^2 - a^2 == b^2)) 
                                      then return(a,b,c)
                                      else return ()
        else return ()

which does not compile. When I put in (a,b,c) for the return, it compiles, but obviously it does not give the expected result anymore. How do I return “nothing” in the else branches?

If I put in ((),(),()) as the return values, the compiler gets a “No instance for (Num [a]) arising from the literal ‘1’”

  • 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-29T08:48:32+00:00Added an answer on May 29, 2026 at 8:48 am

    Instead of return (), which is [()], you must produce an empty list, so else [] or, with the generic guard implementation else mzero.

    The success branch produces a list of triples, [(Int,Int,Int)] (or Integer, or another Num type), so the failure branches must produce the same. Since failure means that no triple is found, they shall produce an empty list.

    Note that in the [] monad, return x is just [x] and mzero (from MonadPlus) is the same as fail whatever, namely [].

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

Sidebar

Related Questions

Task: transfer a server side binary tree to client. I got this task in
Simple task like make AJAX request , pass one parameter and return result, can
My task for this evening is to show and hide a div (eventually two
Task: Write timestamps into MS SQL database table every second. Solutions: External application which
task: {x*y such that x belongs to S & y is iteration count }
My task is simple: make a post request to translate.google.com and get the translation.
Task 1: Read each row from one csv file into one seprate txt file.
Task: Process 3 text files of close to 1GB size and turn them into
Task: implement paging of database records suitable for different RDBMS. Method should work for
Task at hand — I have three versions of some code, developed by different

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.