Skip to content
circular17 edited this page Oct 4, 2023 · 6 revisions

A record represents a collection of named values. While they bear similarities to objects in object-oriented programming with attributes such as properties and constructors, records in Append have their distinctive characteristics. Records can either be anonymous or have a designated type name.

Here is an anonymous record: let myPoint = {| x: 3.0, y: 45.4 |}

It is possible to clone the record and:

  • Modify one member: myPoint <| x: 4.0 will give the record {| x: 4.0, y: 45.4 |}
  • Remove one member: myPoint <| !y will give the record {| x: 3.0 |}

To define a named record type, introduce type with the type keyword:

type pointF {| x/y float |}

// usage with hashtag
let p1 = #pointF {| x: 3.0, y: 45.4 |}

// it is impossible to remove a member from a named record,
// so the next line will trigger a compiler error
let justX = p1 <| !y

It is possible to define a generic type by prefixing the generic parameter and a dash.

type T-point {| x T, y T |}
var p2 = #int-point {| x:2, y: 3 |}

To inherit from another record, one can use the splat operator .... It is possible to combine multiple types:

type T-altitude {| z T |}
type T-point3 {| ...T-point, ...T-altitude |}
Clone this wiki locally