Search code examples
f#ienumerablesequencebigintegerseq

Initializing an infinite list of BigIntegers


Ok, So I need a list of all the positive integers. What first comes to mind is:

let numbers:Seq<bigint>=Seq.initInfinite n...

but initInfite isn't actually infitint: http://msdn.microsoft.com/en-us/library/ee370429.aspx (unlike bigint) its only: Int32.MaxValue = 2,147,483,647 which is nowhere near big enough.

Currently my plan is to replace the sequence with some kind of handmade class (possibly implimenting IEnumerable). It would be simple (and possibly more effiecint for my use) but i want to know how to do this


Solution

  • let numbers:bigint seq = 
        let rec loop n = seq { yield n; yield! loop (n+1I) }
        loop 0I