f# - Struct for depth-curves in sea-maps -
I am trying to make a straight in #F to represent deep curves in the sea map. It should contain a list of coordinates and float in which the depth is represented (i.e. "4.5 m"). I have made it like this:
type coord = straight val x: float val y: float new (x, y) = {x = x; Y = y} End type DepthCurve = struct Val dorms: List & lt; Coord & gt; Val depth: Float new (list_of_Coords, Depths) = {Coords = list_of_Coords; Depth = depth} finally give myCoord1 = new COORD (1., 2.) myCoord2 = new Coord (3., 4.) MyDepthCurve = new DepthCurve ([myCoord1; myCoord2], 5.)
My problem is that it does not allow me to create polygon and its cord at once:
myDepthCurve = {coords = [[1 .; 2 .]; [3 .; 4.]], 5}
A solution exists for this:
type coord = {x: float; Y: float} type 'a deep crawl = {cosures:' a list;} let my depipment = {cos = [[1 .; 2.]; [3 .; 4.]]} ;;
But this does not even give me a float in depth indicating straight, and it does not allow me to restrict the list types.
How do I make the best from both worlds?
Object types that you create are standard with a constructor. NET structures - they do not have a special F # -record-initialization sytnax ( {...}
).
For your problem, you just type a little wrapper function:
Repeat Depth Cows = New Depth Curves (for [x, y] in Cords - & gt; New Coord (X, Y)], depth)
is used like this
let's testCurve = curve 10. [(1., 2 .); (3., 4); ...]
While declaring your structures in short record syntax, you should do this:
type coord = float * float // Type-aka DepthCurve = {coords: Coord list for 2D float-type type; Depth: Float} Meri Crowar = {Cosos = [(1., 2.); ...], Depth = 42.}
There is no reason why you should use the general list, just specify Coord listing
(whose Meaning list codes
). And please keep in mind the difference between a list ( [1; 2; 3]
) and a tuple ( (1, 2, 3)
) The latter are more suitable to represent the corner.
Please take a look at F # structures and types.
Comments
Post a Comment