|
Dieser Artikel wurde manuell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
Datensätze (F#)
[ attributes ]
type [accessibility-modifier] typename = {
[ mutable ] label1 : type1;
[ mutable ] label2 : type2;
...
}
member-list
type Point = { x : float; y: float; z: float; } type Customer = { First : string; Last: string; SSN: uint32; AccountNumber : uint32; }
let mypoint = { x = 1.0; y = 1.0; z = -1.0; }
type Point = { x : float; y: float; z: float; } type Point3D = { x: float; y: float; z: float } // Ambiguity: Point or Point3D? let mypoint3D = { x = 1.0; y = 1.0; z = 0.0; }
let myPoint1 = { Point.x = 1.0; y = 1.0; z = 0.0; }
type MyRecord = { X: int; Y: int; Z: int } let myRecord1 = { X = 1; Y = 2; Z = 3; }
let myRecord2 = { MyRecord.X = 1; MyRecord.Y = 2; MyRecord.Z = 3 }
let myRecord3 = { myRecord2 with Y = 100; Z = 2 }
type Car = { Make : string Model : string mutable Odometer : int } let myCar = { Make = "Fabrikam"; Model = "Coupe"; Odometer = 108112 } myCar.Odometer <- myCar.Odometer + 21
// Rather than use [<DefaultValue>], define a default record. type MyRecord = { field1 : int field2 : int } let defaultRecord1 = { field1 = 0; field2 = 0 } let defaultRecord2 = { field1 = 1; field2 = 25 } // Use the with keyword to populate only a few chosen fields // and leave the rest with default values. let rr3 = { defaultRecord1 with field2 = 42 }
type Point3D = { x: float; y: float; z: float } let evaluatePoint (point: Point3D) = match point with | { x = 0.0; y = 0.0; z = 0.0 } -> printfn "Point is at the origin." | { x = xVal; y = 0.0; z = 0.0 } -> printfn "Point is on the x-axis. Value is %f." xVal | { x = 0.0; y = yVal; z = 0.0 } -> printfn "Point is on the y-axis. Value is %f." yVal | { x = 0.0; y = 0.0; z = zVal } -> printfn "Point is on the z-axis. Value is %f." zVal | { x = xVal; y = yVal; z = zVal } -> printfn "Point is at (%f, %f, %f)." xVal yVal zVal evaluatePoint { x = 0.0; y = 0.0; z = 0.0 } evaluatePoint { x = 100.0; y = 0.0; z = 0.0 } evaluatePoint { x = 10.0; y = 0.0; z = -1.0 }
Point is at the origin. Point is on the x-axis. Value is 100.000000. Point is at (10.000000, 0.000000, -1.000000).
type RecordTest = { X: int; Y: int } let record1 = { X = 1; Y = 2 } let record2 = { X = 1; Y = 2 } if (record1 = record2) then printfn "The records are equal." else printfn "The records are unequal."