The Freya Programming Language

Records

See also

Record types are very similar to class types, except they are value types, instead of reference types.

Record declarations

There are several restrictions regarding records:

Vector = record
public
    constructor(X, Y, Z: Double);

    property X, Y, Z: Double;

    method Equals(Other: Object): Boolean; override;
    method GetHashCode: Integer; override;

static public
    method= (V1, V2: Vector): Boolean;
    method<>(V1, V2: Vector): Boolean;

end;

Record implementations are identical to class implementations.

Overridable methods

If you need to compare instances from a record type, you should redefine the Equals method and the GetHashCode method. These methods are inherited from the System.Object class, but the inherited implementation for Equals, from System.Value type, is based on reflection, and it is not efficient at all.

Another consequence, if you redefine Equals and GetHashCode, is that you must redefine the equality and inequality operators.

See also

The Freya Programming Language
Type declarations
Nested types
Class declarations
Nullable types
Interface types
Delegate types
Type members