OCaml records
In OCaml, records are a way to group related values of different types together into a single composite value. Records are defined using the type keyword, with a name and a list of fields.
type point = {
x : float;
y : float;
}
To create a value of this record type, we use the syntax { field1 = value1; field2 = value2; ... }. For example:
let origin = {
x = 0.0;
y = 0.0;
}
We can access the fields of a record using the . operator. For example:
origin.x ;;
- : float = 0.
Read other posts