I'm trying to make a struct in F# for representing depth curves in a sea map. It has to contain a list of coordinates and a float telling what depth is represented (eg. "4.5 meters"). I have made it this way:
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. )
My problem is that this doesn't let me create the Polygon and its Coords in one go, like this:
let myDepthCurve = {coords=[[1.;2.];[3.;4.]] , 5}
There do exist a solution for this:
type Coord = { X : float; Y : float }
type 'a DepthCurve = {coords: 'a list;}
let myDepthCurve = {coords=[[1.;2.];[3.;4.]]};;
but it doesn't let me have the depth-indicating float in the struct as well, and it doesn't let me restrict types of the list to be only Coords.
How do I combine the best from both worlds?