Record types
Mental process
As the name implies, a record is a mental inventory or a “collection” of:
- characteristics of a “thing” (or a whole class of things)
- attributes of an observable process (everything is a process)
- properties of an abstract mathematical “object”.
In theory, the mind does not have to record all the attributes, and each slot is independent from each other.
The mind solves the ordering problem by using words (of a human language) as “tags” for its mental concepts (which are different from memories or feelings) so the access is position-independent.
Abstraction
A record (as a whole) corresponds to labeled (tagged with symbols) Cartesian Product, meaning that each value has a unique label or a tag associated with it.
This means that the access is name-based (or position-independent), rather than location-based, which depends on a particular ordering.
Vector space
Just like it is with a Cartesian Products, each value ranges over a certain Set (not necessarily the same) and the product covers a whole vector space, which is just a Set of all Pairs (points on a plane) or Triples or whatever.
It is less wrong to say that a “covers” a vector space (of all possible n-dimensional coordinates or “points”) rather than “produces” it.
Typing
“Naturally”, each record, at least in theory, corresponds to its own type, assuming that it characterizes some unique phenomena or a class of “objects”, and the type as a whole is superimposed on (by the mind) or covers a whole vector space of whatever it supposed to represent.
It is reasonable to have a distinct module for each record-type.
Semantics
A record is just a Set of typed “slots” labeled with symbols, where symbols are merely tags for corresponding typed values. Each “slot” could be viewed as a mapping (an ordered pair symbol -> typed value) just like words maps to mental concpets.
As an implementation detail, every record has a particular order, immaterial at the higher (semantic) level.
If we will try to consider the Set of all possible records instances (withing a given record-type) we will get a vector space (as a whole).
A vector space of all Vechicles
, which contains a vector space of
all Toyotas
in it.
Representation
At an implementation level there is always an actual “concrete” representation.
A record represents a collection of values stored together as one, where each component is identified by a different slot’s name.
Collection of records is a table (as in an SQL database).
Each record (structured data) had its own type and, ideally, its own module.
The first step is to cut down the definitions of each record to contain just the information unique to that record (Normalization in SQL)
The set of fields available in a record is always the same.
patterns for types with a fixed structure, like records and tuples, are irrefutable, unlike types with multiple tags (data-counstructors) like lists and variants
a pattern can mention only a subset of the fields in the record.
Functional Updates
update only selected fields, leaving others (whatever they are) unchanging
{ <record> with <field> = <value>; <field> = <value>; … }
With Fields extension
The with fields annotation at the end of the declaration of a record type will cause the extension to be applied to a given type declaration. The same as Common Lisp - creates a set of funtions for accessing slots and modifying them. Creates module named Fields