在F#中使用记录没有简单的方法?
在F#中,我可以这样做:在F#中使用记录没有简单的方法?,f#,instantiation,record,F#,Instantiation,Record,在F#中,我可以这样做: type coord = float * float //Type for a 2D-float-tupple let myDepthCurve1 = { coords = [(1., 2.); (3., 4.)]; depth = 9.4 } 但我不能这么做: type coord = { longitude : float; latitude : float } //Type for a 2D-float-record let myDepthCurve1 = {
type coord = float * float //Type for a 2D-float-tupple
let myDepthCurve1 = { coords = [(1., 2.); (3., 4.)]; depth = 9.4 }
但我不能这么做:
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 }
当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 }
我认为如果您使用大括号而不是圆括号来构造“inline”记录表达式,那就好了。假设类型如下: 类型x={coords:coord list;深度:float} 你可以这样写: 设myDepthCurve1={coords=[{经度=1;纬度=2.}; {经度=3;纬度=4.}];
深度=9.4} 谢谢各位。小细节,大区别。除了它应该是;在表达式{经度=1.,纬度=2.}中,和的用法没有任何系统模式;在F#中?固定。模式很简单-逗号是一个元组生成运算符(注意,它不需要括号),所以其他所有操作都必须使用分号来消除歧义。