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

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

android - How to delete or change the searchview icon inside the SearchView actionBar? -

c++ - Msgpack packing bools bug -