Have you tried making 'one' and 'two' mutable? this would allow for deferred/alternate assignments in multiple constructors. If you are looking for a single instance of your type to only ever have 'one' or 'two' (as opposed to both), I would use a discriminated union, rather than a constructed class.

By on 12/31/2008 9:38 AM ()

Hi Pualmichael,

Yes, in a single instance of my type it will only have "one" or "two". I think discriminated union will work here for me.

Thanks,

Aaron

By on 1/1/2009 11:42 AM ()

Hi,

Unless you have some other reasons to do so, I wouldn't make your fields mutable.

Using a disciriminated union here is good advice. If you only need a simple type to encapsulate either a float or an int, such a type already exists, it's called Choice2. I'd also use that type as a field for your class instead of two option types, if you must use a class.

Furthermore, the F# compiler is right: you should give a value to all your fields in your constructor. option types do not get automatically assignned None (this is not the same as null in C#, although it gets compilded that way)

Kurt

By on 1/1/2009 9:33 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