You could also use reference cells for this :

1
2
3
4
5
6
type TestFSharp (id) =
    static let nextId = ref 0 // nextId : int ref = {contents = 0;}
    member x.Id = id
    new () =
        incr nextId // incr : (int ref -> unit)
        TestFsharp !nextId // !xxx where xxx is ref is an alias for accessing it's contents.
By on 10/11/2011 6:47 PM ()

How about this:

1
2
3
4
5
6
7
type TestFsharp(id) =    
    static let mutable _NextId = 0
    member this.Id = id
    new () = 
        _NextId <- _NextId + 1
        new TestFsharp(_NextId)
By on 6/20/2011 11:45 AM ()

Cool- I'll give that a try!

Thanks!

By on 6/20/2011 1:30 PM ()

Ugh- I hate the formatting on this site...

By on 6/20/2011 9:59 AM ()

moved the code above...

By on 6/20/2011 10:27 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