Both forms are intended to be deprecated, the fact that one is accepted is a bug.

If you want to initialize a record, just give vales to all its fields as below. The "{new..." form somewhat conflicts with object expressions in the language grammar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 

type Whole1 =
    { the1 : int
      the2 : int
    }      
      
let test1 =
    { the1 = 1
      the2 = 2
    }

type Whole =
    { The1 : int
      The2 : int
    }      
      
let test =
    { The1 = 1
      The2 = 2
    }
By on 2/12/2010 9:48 AM ()

I used the "new" syntax to solve ambiguities. Is there a new recommended way of doing this? Type constraints maybe, as in this example (in two different ways):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
type Foo =
    { The1 : int
      The2 : int
    }      
    
type Bar =
    { The1 : int
      The2 : int
    }    
      
let aFoo : Foo =
    { The1 = 1
      The2 = 2
    } 
    
let anotherFoo =
    { The1 = 1
      The2 = 2
    } : Foo
By on 2/12/2010 11:01 AM ()

Personally as a matter of style I always like qualifying the first field, as below. I expect there are a number of things you can do to make the type inference work out the desired way, though.

1
2
3
4
5
6
7
8
type A =
    { X : int
      Y : int }
type B =
    { X : int
      Y : int }
let someA = { A.X = 3; Y = 4 }
let someB = { B.X = 3; Y = 4 }
By on 2/12/2010 12:36 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