lol*_*rup 0 f# record instantiation
在F#我可以这样做:
type coord = float * float //Type for a 2D-float-tupple
let myDepthCurve1 = { coords = [(1., 2.); (3., 4.)]; depth = 9.4 }
Run Code Online (Sandbox Code Playgroud)
但我不能这样做:
type coord = { longitude : float; latitude : float } //Type for a 2D-float-record
let myDepthCurve1 = { coords = [(longitude = 1., latitude = 2.); (longitude = 3., latitude = 4.)]; depth = 9.4 }
Run Code Online (Sandbox Code Playgroud)
当coord类型记录中的字段被标记时,我是否无法一次性创建我的深度?
你应该{}用于记录,而不是().即:
type coord = { longitude : float; latitude : float } //Type for a 2D-float-record
let myDepthCurve1 = {
coords = [ { longitude = 1.; latitude = 2. };
{ longitude = 3.; latitude = 4. }];
depth = 9.4 }
Run Code Online (Sandbox Code Playgroud)