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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:27:55+00:00 2026-05-22T15:27:55+00:00

Define a list: nat2::[(Integer, Integer)] that contains all pairs of nonnegative integers ordered by

  • 0

Define a list:

nat2::[(Integer, Integer)]

that contains all pairs of nonnegative
integers ordered by the relation known
from the proof of Cantor theorem:

(x1,y1) < (x2,y2) <=> x1+y1 < x2+y2 v (x1+y1=x2+y2 ^ x1 < x2)

[^- means alternative]

such that:

nat2 = [(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3),(1,2),(2,1),(3,0),...]

Hint:

definition should fit in one
line and be shorter than 45
characters. Notice that the sum of
coordinates of points laying on on the
same diagonal is constant.

I made some definition, but am not sure if it is correct, could you check/repair/give tips:

nat2::[(Integer,Integer)]
nat2=[(a,b-a)|b<-[0...],a<-[0...b]]

EDIT: CHANGED TO:

nat2 :: [(Integer,Integer)] 
nat2 = [(a,b-a) | b <- [0..], a <- [0..b]]

with result:

Prelude> :load "nat2.hs"
[1 of 1] Compiling Main             ( nat2.hs, interpreted )
Ok, modules loaded: Main.
*Main> take 10 nat2
[(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3),(1,2),(2,1),(3,0)]
  • 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-22T15:27:56+00:00Added an answer on May 22, 2026 at 3:27 pm

    You have a syntax error (did you try running it and checking the output?)

    Prelude> [(a,b-a)|b<-[0...],a<-[0...b]]
    
    <interactive>:1:14:
        A section must be enclosed in parentheses thus: (0 ...)
    

    Because you only need two .. in the list enums:

    Prelude> take 10 [(a,b-a)|b<-[0..],a<-[0..b]]
    [(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3),(1,2),(2,1),(3,0)]    
    

    Looks reasonable, but you are the best to judge.

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

Sidebar

Related Questions

I want to define a generator from a list that will output the elements
I've been given the question: Define a predicate ordered/1, which checks if a list
i would like to define a list(List of Bank Customer) from predicate and process
I want to union, merge in a List that contains both references, so this
Is it possible to define a list with a fixed size that's 100? If
I have the following items (define itemslist (list 'a1 'b2 'c3 (list 'z1 'z2)
Suppose I have a list of #define s in a header file for an
Is it possible to define a recursive list comprehension in Python? Possibly a simplistic
(define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list)
POSIX.1e was going to define ACL ( Access Control List ) mechanisms for POSIX

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.