Types, contracts and substitutability
The FormaSL type system determines how the language’s constructs are formed, which guarantees accompany their use and under which conditions a construct can take the place of another. It participates in defining entities, relations, roles, references and semantic operations, connecting the source declarations to the contracts used during computation.
Types have semantic identity, identifiable contracts and compatibility rules. The language also allows type parameters, specialization, subtyping and different forms of exposing definitions. These mechanisms are interpreted over a static environment of declarations and resolved references.
The type system operates together with the metagraph and the ontologies. The static contracts define the formation and substitution conditions of the constructs; the ontologies organize domain categories and commitments; the situated classifications express positions about concrete referents.
Formation and resolution of types
A type declaration introduces an identity recognized by the language and a contract determining the conditions of its use. Types can be referenced by qualified names, used in relation declarations or used in operation signatures. Resolution binds each reference to the pertinent declaration under a basis of modules, interfaces, imports and revisions.
FormaSL distinguishes the formation of a type expression, the validity of a declaration and the compatibility judgments between types. A well-formed expression uses resolved references and admissible arguments. A well-formed declaration meets its category’s rules. Compatibility, in turn, is determined by the guarantees and relations established by the involved contracts.
Those verifications belong to the language’s static environment. The elaboration of a program uses the admitted declarations and their resolution bases to build an explicit semantic representation, in which the relevant identities, revisions and static dependencies remain recoverable.
Identity and type contract
Type identity determines which semantic type is being referenced. The type contract establishes the guarantees other constructs can use, and its revision identifies the version of those guarantees considered in a determined judgment.
The same identity can cross contract revisions. Historical use remains bound to the revision under which it was formed, while new declarations and operations can use a later revision. The equivalence between contracts and the subtyping relation are judgments of their own, determined over the corresponding bases.
Consider an industrial maintenance domain. A declaration can introduce the type of an equipment and offer static guarantees used by relations referencing it. A contract revision can modify that type’s conditions of use. The semantic referent of an equipment and the identity of the type a construct binds to remain different questions: one describes the domain element; the other governs the construct’s formation and compatibility.
The physical representations used to realize those types can vary. The relation between a type’s semantic identity and its representation in Rust, in a serialized format or in a database is established at the appropriate realization boundaries.
Declarations, aliases and visibility
FormaSL has declarative forms for named, parameterized, distinct, opaque types and aliases. Each form determines how identity and contractual information are exposed to consumers.
A type alias adds a designation for an already existing identity. The new name participates in resolution without introducing another semantic type.
A transparent distinct type has its own identity and can expose selected information of its definition or representation. Transparency allows using the information published by the contract, preserving the type’s distinct identity.
An opaque type exposes its identity and the guarantees made available by the interface, keeping other definition details under the responsibility of the declaring module. The consumer uses the visible contract, even when the internal implementation or the representation change.
Module interfaces control the visibility of those definitions. A module can export a type with a determined set of guarantees, and another module can use it through the published interface. Alias, re-export and interface exposure have specific effects on name bindings and on the available information, preserving the identity of the referents they designate.
Parameters and polymorphism
FormaSL admits parametric polymorphism in type and relation declarations. A parameterized declaration establishes type variables that will be bound to arguments at instantiation. The parameters can have bounds, and each argument must satisfy the corresponding conditions.
That capability allows defining reusable contracts without fixing in advance all the participating types. The ClassifiedAs<T> relation of the std::world::classification library, for example, uses a parameter for the classified subject’s type, keeping the other roles associated with classification concepts and schemes.
Instantiation verifies the constructor’s resolution, the number of arguments, the formation of the provided types and the declared bounds. When a bound uses subtyping, the applicable subtyping judgment determines the argument’s admissibility.
The compatibility between different instantiations also belongs to the constructor’s contract. A subtyping relation between S and T only propagates to F<S> and F<T> when a variance or substitution rule established for F admits that passage. Thus, the parameterized type’s contract defines the guarantees available for each use.
Specialization and inheritance
Typed specialization allows declaring an explicit relation between a specialized construct and an origin construct. The specialization contract determines which structures and guarantees are inherited, reused or refined.
A maintenance application can define a general equipment type and specializations for equipments of distinct operational classes. Those specializations can share declarative aspects and add specific elements, according to the corresponding contracts.
Specialization organizes the relation between the declarations. Its use as a substitute of the origin type is determined separately by the subtyping judgment. This lets structures be reused across types even when their contracts do not authorize all the same uses.
The cycles of strict specialization follow the language’s formation rules. The recursive relations present in the metagraph, such as equipments referencing other equipments in a configuration, have their own contracts and can form cycles without altering the type identity rules.
Subtyping and safe substitution
Subtyping expresses the possibility of using an admissible element of type S where a consumer requires type T. That substitution preserves all the static guarantees the consumer of T is entitled to use.
The judgment considers the target contract’s guarantees and verifies whether the candidate type satisfies them under the applicable rules. An explicit subtyping declaration participates in that process according to the language’s acceptance conditions. There are also relations authorized by properties such as reflexivity, transitivity and rules proper to determined declaration categories.
In a maintenance system, suppose an operation accepts an equipment type whose contract ensures a determined semantic interface of identification and reference. A specialized type can be used in that position when its contract preserves those guarantees. Additional characteristics of the specialization remain available in the uses that know them, while the consuming operation can depend on the properties ensured by the required type.
Substitution can also involve relation and role contracts. When a relation requires certain guarantees of participation, cardinality, multiplicity or ordering, the corresponding static rules need to be considered to preserve what its consumers use.
Conversion is a different operation. It establishes how to produce a target construct from another, under its own contract. Subtyping, in contrast, authorizes the substitutive use of a construct within the already established guarantees.
Types and relation contracts
Relation contracts use the type system to define admissible participants and references to semantic elements. A role can indicate a participant type or use another admissibility contract appropriate to the relation.
In the typed role-incidence metagraph, participants can be entities, relations or other referents admitted by the formation rules. An inspection relation, for example, can define roles for the inspected equipment, the responsible party and the recorded result. Typing contributes so that each participation is formed according to its contract.
Participation rules cover, when material, number of occurrences, multiplicity, repetition, ordering, keys and qualifications associated with the roles. Those guarantees belong to the relation’s contract and are expressed under its semantic unity of counting and correlation.
A validation restriction can later examine a set of information under specific criteria. An ontological axiom can establish conditions interpreted within a theory. A constitutive participation guarantee defines what the relation admits or requires in its own formation. The three structures use related information, each under the contract responsible for its interpretation.
Types, ontologies and situated classifications
An ontological category represents a conceptual commitment under an ontology. A situated classification relates a referent to a category in a determined scheme, context or attributable position. The language type participates in static judgments about declarations and constructs.
An equipment can be classified as critical by an operation team and receive another evaluation under a maintenance scheme. Those positions can coexist and change over time. The typed declarations used to represent the equipment and the relations it participates in keep their identity and contracts.
An application can query situated classifications and use them in analyses, inferences, validations or decisions. The operations interpret those classifications as domain information. The static type rules continue being determined by the environment of resolved declarations and contracts.
That separation also guides the use of ontological concepts in typed relations. A correspondence between an ontological category and a type can be declared or used by an operation under its own contract, respecting the meaning of both.
Typing, results and governance
Typed formation is one of the conditions for using a construct in a semantic operation. Other judgments apply their own contracts over inputs and results.
Validation examines information under restrictions and a validation world. Conformance expresses the corresponding judgment. Admission and authorization depend on governance bases, while a decision constitutes an attributable transition under declared conditions. Those stages can consume typed constructs and add domain or authority judgments.
Computational results also have a semantic status. A typed output signature specifies aspects of the static interface of the produced content; the result contract determines whether it is a query answer, an inference consequence, an analytical value or another result, including its bases, dependencies and completeness conditions.
When composing operations, FormaSL verifies the static formation of the inputs and the acceptance conditions defined by the consumer. Type compatibility participates in that verification, together with the result’s status, its interpretation basis and the semantic requirements of the next operation.
Historical contracts and realization
Type judgments are relative to an identifiable static basis. It gathers the declarations, interfaces, bindings and revisions needed to interpret each construct. When those elements evolve, historical judgments remain related to the originally used basis.
Elaboration transforms the resolved and admitted program into an explicit semantic program, preserving the relevant identities and static guarantees. The contracts thus reach the composition, realization and execution stages as information defined by the language.
Realization can select different physical representations, storage mechanisms or execution components. The binding between semantic types and operational representations follows the applicable contracts, letting the implementation evolve while the published guarantees continue being respected.
Related documentation
The Logical architecture and metagraph presents the relations and participations using typed contracts. Ontologies and semantic theories develops the conceptual categories and domain classifications. Semantic operations and transitions describes the consumers of those constructs, while Semantic invariants establishes the distinctions preserved throughout computation.