f# - Is there a more idiomatic way to generate an infinite sequence of uint64? -
let makeidgenerator startvalue = let index : uint64 ref = ref startvalue fun () -> let result = !index index := !index + 1ul result
what need generator function has type unit -> uint64
shown above.
the code above works uses reference variable memoize state of generator.
trying use infinite sequence in seq.initinfinite (fun -> i)
not work sequence inherently uses uint32
state.
does here know way without reference variable? maybe means of recursion , yield or so?
thanks in advance.
you can use seq.unfold
:
let makeidgenerator (startvalue : uint64) = seq.unfold (fun -> some((i, i+1ul))) startvalue
Comments
Post a Comment