vyrn

Records, enums, match

A record is a shape. An enum is a choice. match covers every case, and the compiler counts them.

Records

A record type lists fields. Compatibility is by shape: a value with more fields fits where fewer are wanted, with no cast and no base class. This is width subtyping, and it is the whole inheritance story.

Fields of a mut binding are assigned in place. A record that owns heap data — a String field, for example — is moved by an assignment, so copy() is how both sides keep a value.

hello, Ada was 36 now 37

Enums

An enum value is exactly one variant, and a variant can carry a payload. There is no tag field to keep in step with a union, because the tag is the type.

match must cover every variant. Leave one out and the file does not compile. That is what makes an enum safe to extend: add a variant, and the compiler lists every place that has to answer for it.

circle of radius 2 rect 3 by 4 a point

match expressions

match answers with a value, so a binding takes it directly and there is no mutable slot to fill in each arm.

if let reads one variant when the others need no arm. while let does the same in a loop, and stops when the pattern stops matching.

warning: disk is filling world at byte 7 zebra is not there