I don't have a machine handy to check, but if you change

let defaultX = { a=0; b=0; c=None; d=None }

let x = { defaultX with a=1; b=2 }

does this work, and does it give you want you want?

By on 3/26/2009 5:08 PM ()

Not really because the second statement doesn't force me to provide an 'a' or 'b' anymore. For instance, if I have lots of fields and accidentally forget to provide one in the second statement it will use the default of a=0/b=0 which isn't necessarily valid.

By on 3/26/2009 8:22 PM ()

OK, so you could add a member to the record type to force you to provide the other values and validate them.

By on 3/26/2009 9:43 PM ()

Right, does this fit the bill?

1
2
3
4
5
6
7
8
9
10
11
type X = {
   a : int
   b : int
   c : int option
   d : int option
   }
   with 
   static member DefaultWith(a, b) =
     { a=a; b=b; c=None; d=None }

let x = X.DefaultWith(a=1,b=2)
By on 3/26/2009 10:02 PM ()

Perfect!

Thanks guys!

By on 3/28/2009 5:26 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