seq.unfold

Seq.unfold explanation in F#

*爱你&永不变心* 提交于 2020-01-03 17:15:35
问题 I am trying to create a sequence lazily by using F#. The sequence is defined as follows: The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Here is what I have so far but it dosn't seem to work: let tri_seq = 1.0 |> Seq.unfold (fun x -> match x with | _ -> Some (x, 0.5*x*(x + 1.0))) Thank you very much who can help me figure out how unfold works. Thanks Edit: I marked the first answer as

Why is using a sequence so much slower than using a list in this example

☆樱花仙子☆ 提交于 2019-11-27 21:15:07
Background: I have a sequence of contiguous, time-stamped data. The data-sequence has holes in it, some large, others just a single missing value. Whenever the hole is just a single missing value, I want to patch the holes using a dummy-value (larger holes will be ignored). I would like to use lazy generation of the patched sequence, and I am thus using Seq.unfold. I have made two versions of the method to patch the holes in the data. The first consumes the sequence of data with holes in it and produces the patched sequence . This is what i want, but the methods runs horribly slow when the

Why is using a sequence so much slower than using a list in this example

删除回忆录丶 提交于 2019-11-27 04:30:12
问题 Background: I have a sequence of contiguous, time-stamped data. The data-sequence has holes in it, some large, others just a single missing value. Whenever the hole is just a single missing value, I want to patch the holes using a dummy-value (larger holes will be ignored). I would like to use lazy generation of the patched sequence, and I am thus using Seq.unfold. I have made two versions of the method to patch the holes in the data. The first consumes the sequence of data with holes in it