Something that would do what you want without killing the stack would be

1
2
3
4
5
let rec sequence input =
    seq {
        yield input //or yield f input, if you want to transform the input
        yield! sequence (input+1) //last call --> tail recursive
    }

Somewhat harder to read, but faster, is using Seq.unfold:

1
let sequence2 input = Seq.unfold (fun n -> Some (n,n+1)) input
By on 2/8/2010 1:02 AM ()

Thanks. That's exactly what I was looking for.

By on 2/9/2010 11:55 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper