海図で深度曲線を表すために F# で構造体を作成しようとしています。座標のリストと、表現される深さを示すフロートを含める必要があります (例: "4.5 メートル")。私はこのようにしました:
type Coord =
struct
val X : float
val Y : float
new(x,y) = { X = x ; Y = y }
end
type DepthCurve =
struct
val Coords : list<Coord>
val Depth : float
new(list_of_Coords, depth) = { Coords = list_of_Coords ; Depth = depth}
end
let myCoord1 = new Coord(1.,2.)
let myCoord2 = new Coord(3.,4.)
let myDepthCurve = new DepthCurve([myCoord1;myCoord2] , 5. )
私の問題は、次のように、ポリゴンとその座標を一度に作成できないことです。
let myDepthCurve = {coords=[[1.;2.];[3.;4.]] , 5}
これには解決策があります:
type Coord = { X : float; Y : float }
type 'a DepthCurve = {coords: 'a list;}
let myDepthCurve = {coords=[[1.;2.];[3.;4.]]};;
しかし、構造体に深さを示すフロートを持たせることも、リストの型を Coords だけに制限することもできません。
両方の長所をどのように組み合わせますか?