Structure
type TextPos = struct
line : u32
char : u32
The TextPos structure contains two fields of type u32.
let position = TextPos line = 1
char = 8
position is an immutable binding private to a file.
let position = TextPos
line = 1
char = 8
The field values definition has been moved to a new line.
let line = 1
let char = 8
let position = TextPos =line =char
The short syntax is used because the fields and bindings have the same names.
let position = TextPos 1 8
Fields receive values positionally.
let position = TextPos.new
If all fields of a structure are numeric, new initializes them to zero.
type TextPos
def left = TextPos line (char - 1)
The TextPos structure is opened to add the left method.
type TextPos
def move_left @mut =
char -= 1
let mut position = TextPos 1 8
position.move_left
The @mut attribute on the move_left method makes fields writable. Such a method can only be called on a mutable structure.