Expand description
The type language: base types, the mutable (union-find) representation
of type/row variables, monomorphic and polymorphic types, and
level-based generalization. Mirrors mono_type_main / poly_type /
kind in v0.0.6’s src/frontend/types.cppo.ml, with two deliberate
departures documented at their definitions:
- Generalization is level-based (Rémy levels), not v0.0.6’s
quantifiabilityflag. SeeTypeContext,generalizeandinstantiate. - Extensible records are a first-class row type (
Row::Empty/Row::Var/Row::Cons), not v0.0.6’s closedRecordTypeplus a plain type variable carrying aRecordKindlabel-subset constraint. SeeRow.
Structs§
- CmdArg
Type - One command argument type:
tyfor a mandatory argument, orty?for an optional one (v0.0.6:MandatoryArgumentType/OptionalArgumentType, types.cppo.ml:326-328).optional/opt_labelsare version-discriminated by construction: underV0_0(positional model)optionalmarks a whole-slotty?optional andopt_labelsis always empty; underV0_1(labeled model, upstreamCommandArgType of typ LabelMap.t * typ,types.cppo.ml:214)optionalis alwaysfalseandopt_labelscarries this slot’s?(l:τ,…)bundle — a CLOSED map (no row variable: upstream discards one if written,parser.mly:866’sTODO (error)). Kept sorted by label at every producer (command_scheme’s harvest,lower_type_atom’s sig lowering) sounify/Display/sealing are order-insensitive — seeunify_cmd_args’s zip-equal equal-domain test. - Poly
Type - A type scheme: a monomorphic body plus the set of that body’s free variables which are quantified over it.
- RowVar
Ref - TyVar
Ref - A reference-counted handle to a type variable’s union-find cell. Cloning
a
TyVarRefshares the same cell (this is the union-find “pointer”); identity (not structure) is whatunifyandgeneralizecompare. - Type
Context - Per-inference-run state: the level stack for generalization, and a
counter for fresh variable ids (see
FRESH_ID’s doc comment for whyinstantiate/unifyuse a different counter than this one — the two never need to agree, since identity is always by pointer).
Enums§
- Base
Type - Primitive types with no internal structure — the subset of v0.0.6’s
base_type(types.cppo.ml:255) that this port’s primitives need. (EnvType/RegExpType/InputPosTypeare unused and left out; add them when a primitive needs them.) - Kind
- The kind of a free type variable.
- Mono
Type - A monomorphic type. Mirrors v0.0.6’s
mono_type(thetype_mainvariant instantiated atmono_type_variable_info ref), minusSynonymType(no type synonyms in this port) and withRow-based records instead of a closedRecordType(seeRow). - Row
- An extensible record row: a sequence of
label : typebindings ending either inEmpty(a closed record — exactly these labels and no others) or inVar(an open record — at least these labels, plus whatever the row variable’s eventual binding adds). - Stage
- Which stage an expression is being read at (upstream’s
stage,types.cppo.ml:400-403).
Functions§
- generalize
- Quantify every free variable in
tywhose level is deeper thanlevel(i.e. was created after entering the let binding being generalized). Typical usage: - instantiate
- Instantiate a scheme: replace every quantified variable with a fresh
one at
level, leaving everything else in the body shared as-is. - resolve
- Follow
Var(_)→Bound(ty)links until reaching either a free variable or a non-variable type. Does not recurse into the structure of compound types (that’s what makes it “shallow”: aFuncwhose domain is itself a bound variable is returned as-is, domain still unresolved) — callers that need a fully dereferenced tree shouldresolveagain at each level as they recurse, which is exactly whatunifyandDisplaydo. - resolve_
row - The row analogue of
resolve,Cowfor the same reason.