Error in merging two sequences of timestamps to yield strings
Posted
by
AruniRC
on Stack Overflow
See other posts from Stack Overflow
or by AruniRC
Published on 2012-06-22T10:48:38Z
Indexed on
2012/06/22
15:16 UTC
Read the original article
Hit count: 229
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.
© Stack Overflow or respective owner