Skip to main content

Module types

Module types 

Source
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:

  1. Generalization is level-based (Rémy levels), not v0.0.6’s quantifiability flag. See TypeContext, generalize and instantiate.
  2. Extensible records are a first-class row type (Row::Empty / Row::Var / Row::Cons), not v0.0.6’s closed RecordType plus a plain type variable carrying a RecordKind label-subset constraint. See Row.

Structs§

CmdArgType
One command argument type: ty for a mandatory argument, or ty? for an optional one (v0.0.6: MandatoryArgumentType / OptionalArgumentType, types.cppo.ml:326-328). optional/opt_labels are version-discriminated by construction: under V0_0 (positional model) optional marks a whole-slot ty? optional and opt_labels is always empty; under V0_1 (labeled model, upstream CommandArgType of typ LabelMap.t * typ, types.cppo.ml:214) optional is always false and opt_labels carries this slot’s ?(l:τ,…) bundle — a CLOSED map (no row variable: upstream discards one if written, parser.mly:866’s TODO (error)). Kept sorted by label at every producer (command_scheme’s harvest, lower_type_atom’s sig lowering) so unify/Display/sealing are order-insensitive — see unify_cmd_args’s zip-equal equal-domain test.
PolyType
A type scheme: a monomorphic body plus the set of that body’s free variables which are quantified over it.
RowVarRef
TyVarRef
A reference-counted handle to a type variable’s union-find cell. Cloning a TyVarRef shares the same cell (this is the union-find “pointer”); identity (not structure) is what unify and generalize compare.
TypeContext
Per-inference-run state: the level stack for generalization, and a counter for fresh variable ids (see FRESH_ID’s doc comment for why instantiate/unify use a different counter than this one — the two never need to agree, since identity is always by pointer).

Enums§

BaseType
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/InputPosType are unused and left out; add them when a primitive needs them.)
Kind
The kind of a free type variable.
MonoType
A monomorphic type. Mirrors v0.0.6’s mono_type (the type_main variant instantiated at mono_type_variable_info ref), minus SynonymType (no type synonyms in this port) and with Row-based records instead of a closed RecordType (see Row).
Row
An extensible record row: a sequence of label : type bindings ending either in Empty (a closed record — exactly these labels and no others) or in Var (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 ty whose level is deeper than level (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”: a Func whose domain is itself a bound variable is returned as-is, domain still unresolved) — callers that need a fully dereferenced tree should resolve again at each level as they recurse, which is exactly what unify and Display do.
resolve_row
The row analogue of resolve, Cow for the same reason.