문제

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 = { coords = [(longitude = 1., latitude = 2.); (longitude = 3., latitude = 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 }

다른 팁

"인라인"레코드 표현식을 구성하기 위해 괄호 대신 Curly Braces를 사용하면 괜찮을 것이라고 생각합니다.

다음과 같은 유형을 가정합니다.

유형 x = {coords : coord list; 깊이 : float} ;;

당신은 이것을 쓸 수 있습니다 :

myDepthCurve1 = {coords = [{longitude = 1.; 위도 = 2}; {경도 = 3.; 위도 = 4.}]; 깊이 = 9.4} ;;

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top