Semantic and Structural Typing
            and combining the two

1. Structural Typing vs. Semantic Typing

Structural Typing

  • Definition: A system is structurally typed when the compatibility of types is determined by their structure, not by their declared name.
  • Example: If two types have the same fields and field types, they are considered compatible, even if they are declared independently.
  • Common in: TypeScript, OCaml, Go.

“If it looks like a duck and quacks like a duck, it’s a duck.”

Semantic Typing

  • Definition: A system is semantically typed when types have meaning, often by being identified with formal ontologies or conceptual categories, not just their structural shape.
  • Example: In RDF/OWL, foaf:Person means “Person” as defined by the FOAF ontology, regardless of what properties it happens to have.
  • Common in: Semantic Web (RDF, OWL), Description Logics.

“If it is a duck (per ontology), it is a duck, even if you can’t see its feathers yet.”


2. The Semantic Web’s Type System

The Semantic Web, powered by RDF(S) and OWL, only supports semantic typing, not structural typing.

  • RDF Classes (rdfs:Class) are essentially semantic labels.
  • Membership in a class is declared via triples: ex:Bob rdf:type foaf:Person.
  • RDF does not care what properties Bob has to be considered a foaf:Person.
  • OWL can specify restrictions on classes (e.g., “all Persons have a name”), but it does not cause the system to behave like a structurally-typed one — it stays at the inference level, not the validation level.

So, RDF is not structurally typed because:

  • There is no notion of a required shape or field set for types.
  • Inference is driven by semantic relationships, not structural compatibility.

3. Why isn’t there a common term for combining structural and semantic typing?

The key reason is historical separation:

  • Programming languages mostly developed structural type systems (especially in ML-family languages, TypeScript, etc.) for reasoning about code.
  • Semantic web / AI focused on meaning and knowledge representation, which is often incomplete and open-world (you might not know all fields).
  • There’s been little cross-pollination because:
    • Structural typing is fundamentally a closed-world assumption: “I know everything about this value.”
    • Semantic typing is fundamentally an open-world assumption: “I may not know all properties, but I know it is a Person.”

Combining them is non-trivial because they seem to philosophically contradict:

  • Structural typing assumes you know the complete shape.
  • Semantic typing assumes you don’t necessarily know the complete shape.

4. Proposal: “Deep Type System”

If you want to merge both:

A Deep Type System is a type system where entities are characterized both by their structure (fields and field types) and by their semantic role (their membership in ontologies), and both are enforceable.

Such a system would:

  • Treat semantic typing as a superclass layer.
  • Treat structural typing as a subclass refinement.
  • Allow types to be validated both by ontology membership and structure conformity.
  • Support open-world inference combined with closed-world validation.

5. Why is this valuable?

  • Semantic web can be made stronger, by being able to check that an ex:Person actually has the structural properties you’d expect.
  • Programming languages could become ontology-aware, allowing knowledge graphs to directly inform type checkers and IDEs.
  • AI reasoning could better interoperate with code-level systems.

TL;DR

  • Structural typing = shape-based
  • Semantic typing = meaning-based
  • Semantic Web = only semantic typing
  • Deep Type System = hybrid of both