(Your example is actually records. Structs include the "struct" keyword).

Records are immutable, so there is no point in having a default field value in your example. I can see some point in having a default value for a mutable field, but F# doesn't support that.

However, you can declare a default record value, then use it to initialise other instances....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type My =
    {  A: bool;
       B: int; }

// Declare a default (immutable) value for My

let defaultMy = { A = false; B = 0 } 

let my1 = { defaultMy with A = true }

// Can't put a default value in the definition
type My2 =
    {  mutable A': bool = false; // ...unexpected symbol "=" in type definition....
       B': int; } 

BTW. pasting whitespace seems to work for spaces. Maybe tabs are a problem.

By on 11/7/2009 3:24 PM ()
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