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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:33:36+00:00 2026-06-11T17:33:36+00:00

if am trying to write a simple function that list of pair of integers

  • 0

if am trying to write a simple function that list of pair of integers – representing a graph and returns a list of integers : all the nodes in a graph
eg if input is [(1,2) (3,4) (5,6) (1,5)]
o/p should be [1,2,3,4,5,6,1,5]
The function is simply returning list of nodes , in the returning list values may repeat as above.
I wrote the following function

fun listofnodes ((x:int,y:int)::xs) = if xs=nil then [x::y] else [[x::y]@listofnodes(xs)]

stdIn:15.12-15.18 Error: operator and operand don’t agree [tycon mismatch
operator domain: int * int list
operand: int * int
in expression:
x :: y.

I am not able to figure out what is wrong.

  • 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-11T17:33:37+00:00Added an answer on June 11, 2026 at 5:33 pm

    first of all you should know what each operator does:
    :: puts individual elemtents into an existing list so that: 1::2::3::[] = [1,2,3]
    @ puts two lists together so that: [1,2] @ [3,4] = [1,2,3,4]

    you can also use :: to put lists together but then it becomes a list of lists like:
    [1,2] :: [3,4] = [[1,2],[3,4]]

    so by writing [x::y] you are saying that x and y should become a list inside a list.

    and you shouldnt use an if statement to check for the end of the list, instead you can use patterns to do it like this:

    fun listofnodes [] = []
      | listofnodes ((x,y)::xs) = x :: y :: listofnodes(xs);
    

    the first pattern assures that when we reach the end of the list, when you extract the final tuple your xs is bound to an empty list which it calls itself with, it leaves an empty list to put all the elements into, so that [(1,2) (3,4) (5,6) (1,5)] would evaluate like this:

    1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 1 :: 5 :: [] = [1,2,3,4,5,6,1,5].

    you could also make it like this:

    fun listofnodes [] = []
      | listofnodes ((x,y)::xs) = [x,y] @ listofnodes(xs);
    

    this way you make a small 2 element list out of each tuple, and then merge all these small lists into one big list. you dont really need the empty list at the end, but its the only way of ensuring that the recursion stops at the end of the list and you have to put something on the other side of the equals sign. it evaluates like this:

    [1,2] @ [3,4] @ [5,6] @ [1,5] @ [] = [1,2,3,4,5,6,1,5].

    also you cast your x and y as ints, but you dont really have to. if you dont, it gets the types ” (‘a * ‘a) list -> ‘a list ” which just means that it works for all input types including ints (as long as the tuple doesnt contain conflicting types, like a char and an int).
    im guessing you know this, but in case you dont: what you call pairs, (1,2), is called tuples.

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

Sidebar

Related Questions

I am trying to write a simple Java function that will take a list
I'm trying to write a simple recursive function that look over list and return
I am trying to write a list function that takes a simple list and
I'm trying to write a simple Vim function that takes the name of a
I'm trying to write a very simple autosuggest type function so that, whenever a
I'm trying to write a simple function in C that would calculate the difference
I trying to write a simple function to call unmanaged code from managed code.
I am trying to write, what I thought was, a simple jQuery function to
I'm trying to write a function that will dump a recursive tree of window
Im trying to write a function that creates set of dynamic sublists each containing

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.