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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:45:10+00:00 2026-06-06T04:45:10+00:00

The code sorts two input sequences – seq01 and seq02 – on the basis

  • 0

The code sorts two input sequences – seq01 and seq02 – on the basis of their timestamp values and returns a sequence that denotes which sequence is to be read for the values to be in order.

For cases where seq02’s timestamp value is lesser than seq01’s timestamp value we yield a "2" to the sequence being returned, else a "1". These denote whether at that point seq01 is to be taken or seq02 is to be taken for the data to be in order (by timestamp value).

let mergeSeq (seq01:seq<_>)  (seq02:seq<_>) = 
    seq { 
            use iter01 = seq01.GetEnumerator()
            use iter02 = seq02.GetEnumerator() 
            while iter01.MoveNext() do
                let _,_,time01 = iter01.Current
                let _,_,time02 = iter02.Current 
                while time02 < time01 && iter02.MoveNext()  do 
                    yield "2"
                yield "1"
    }

To test it in the FSI created two sequences a and b, a={1;3;5;…} and b={0;2;4;…}. So the expected values for let c = mergeSeq a b would have been {"2","1","2","1"…}. However I am getting this error: error FS0001: The type ''a * 'b * 'c' does not match the type 'int'

EDIT

After correcting:

let mergeSeq (seq01:seq<_>)  (seq02:seq<_>) = 
    seq { 
            use iter01 = seq01.GetEnumerator()
            use iter02 = seq02.GetEnumerator() 
            while iter01.MoveNext() do
                let time01 = iter01.Current
                let time02 = iter02.Current 
                while time02 < time01 && iter02.MoveNext()  do 
                    yield "2"
                yield "1"
    }

After running this, there’s another error: call MoveNext. Somehow the iteration is not being performed.

EDIT 2

let mergeRef (seq01:seq<_>) (seq02:seq<_>) = 
    seq{
            use iter01 = seq01.GetEnumerator()
            use iter02 = seq02.GetEnumerator()
            iter01.MoveNext() 
            iter02.MoveNext() 

            let temp01 = ref iter01.Current  //!!using mutable reference
            let temp02 = ref iter02.Current
            
            while iter01.MoveNext() do
                while (iter02.MoveNext()) && ((!temp02) < (!temp01)) do
                    temp02 := iter02.Current
                    yield "2"
                yield "1" 
                temp01 := iter01.Current

            //if seq01 finishes before seq02
            while iter02.MoveNext() do
                yield "2"

       }
  • 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-06T04:45:12+00:00Added an answer on June 6, 2026 at 4:45 am

    After the edit…

    You need to call MoveNext on 2 before accessing current. You’re not updating time02 as you move through 2 in the inner loop. And you’re not checking for the end of sequences properly (e.g. if 2 ends but 1 is going, you’ll try to access 2 after the end).

    (Is this homework?)

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

Sidebar

Related Questions

I am working on a program that take user input for two file names.
We have some code which sorts a list of addresses based on the distance
I have code which works in all sorts of different situations, including when copying
I am trying to code a global lookup table of sorts. I have game
Following code iterates through many data-rows, calcs some score per row and then sorts
After reading all sorts of Stackoverflow postings and various documentation including some on http://code.google.com/p/google-api-java-client/
I got this code to sort an unordered list with regards to their title
I have two programs, sendfile.py and recvfile.py that are supposed to interact to send
I have two DropDownLists that are in a GridView. The DropDownLists only show when
If I have the following code class One: scope = 'first_scope' class Two: scope

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.