I’m using record types in F# to store some simple data, e.g. as follows:
open Vector
type Point =
{
x: float;
y: float;
z: float;
}
static member (+) (p: Point, v: Vector) = { Point.x = p.x + v.x ; y = p.y + v.y ; z = p.z + v.z }
static member (-) (p: Point, v: Vector) = { Point.x = p.x - v.x ; y = p.y - v.y ; z = p.z - v.z }
static member (-) (p1: Point, p2: Point) = { Vector.x = p1.x - p2.x ; y = p1.y - p2.y ; z = p1.z - p2.z }
member p.ToVector = { Vector.x = p.x ; y = p.y ; z = p.z }
I can’t work out whether this will be implemented as a value or reference type.
I’ve tried putting [<Struct>] before the type definition but this causes all sorts of compile errors.
According to this wikipedia article, http://en.wikipedia.org/wiki/F_Sharp_(programming_language), record types are implemented as classes with properties defined.