## Technical Document: Type System Properties and Error Handling
### Overview
The image presents a formal specification of type system properties, error handling rules, and type universal properties in a programming language context. It combines logical assertions, type operations, and error propagation mechanisms using mathematical notation and type theory constructs.
### Components/Axes
1. **Cast Universal Properties Table**
- **Columns**: Bound, Best, Retract Axiom
- **Rows**: Up, Down
- **Notation**: Uses type casts (`⊆`), logical implications (`⇒`), and set operations (`⊆`, `⊇`)
2. **Type Universal Properties Table**
- **Columns**: β (beta), η (eta)
- **Rows**: Type constructors (`+`, `0`, `×`, `1`, `U`, `F`, `→`, `&`, `T`)
- **Notation**: Case analysis, type splitting, and monadic operations
3. **Error Properties Section**
- **Subsections**: ErrBot, StkStrict
- **Notation**: Type refinement (`⊆`), error propagation (`⊆`), and strictness annotations
### Detailed Analysis
#### Cast Universal Properties
| Bound | Best | Retract Axiom |
|-------|------|---------------|
| Up: `x : A - x ⊆ ⟨A' ⇸ A⟩x : A ⊆ A'` | Up: `x ⊆ x' : A ⊆ A' - ⟨A' ⇸ A⟩x ⊆ x' : A` | `x : A ↦ ⟨FA ⇸ F?⟩(ret (⟨? ⇸ A⟩x)) ⊆ ret x : FA` |
| Down: `• : B' - ⟨B ⇸ B'⟩• ⊆ • : B ⊆ B'` | Down: `• ⊆ • : B ⊆ B' - ⟨B ⇸ B'⟩• : B` | `x : U_B ↦ ⟨B ⇸ ?⟩(force (⟨U_? ⇸ U_B⟩x)) ⊆ force x : B` |
#### Type Universal Properties
| Type | β (Beta) | η (Eta) |
|------|----------|---------|
| `+` | `case inl V{x1.E1 | ...} ⇒ E1[V/x1]` | `E ⇒ case x{x1.E[inl x1/x] | x2.E[inr x2/x]}` |
| `0` | - | `E ⇒ abort x` |
| `×` | `split (V1,V2) to (x1,x2).E ⇒ E[V1/x1,V2/x2]` | `E ⇒ split x to (x1,x2).E[(x1,x2)/x]` |
| `1` | `split () to ().E ⇒ E` | `x : 1 ↦ split x to ().E[()]/x : T` |
| `U` | `force M ⇒ M` | `x : U_B ↦ x ⇒ thunk force x : U_B` |
| `F` | `bind x ← ret V; M ⇒ M[V/x]` | `• : FA ↦ bind x ← •; M[ret x/•] : B` |
| `→` | `(λx : A.M) V ⇒ M[V/x]` | `• : A → B ↦ λx : A. • x : A → B` |
| `&` | `π{π ↦ M | π' ↦ M'} ⇒ M` | `• : B₁ & B₂ ↦ {π ↦ π • | π' ↦ π' •} : B₁ & B₂` |
| `T` | - | `• : T ↦ { } : T` |
#### Error Properties
- **ErrBot**:
- `Γ' | · ↦ M' : B'`
- `Γ ⊆ Γ' | · ↦ U ⊆ M' : B ⊆ B'`
- **StkStrict**:
- `Γ | x : B ↦ S : B'`
- `Γ | · ↦ S[U_B] ⊆ U_B' : B'`
### Key Observations
1. **Type Safety**: The Cast Universal Properties enforce safe type casting through bidirectional implications between source and target types.
2. **Monadic Operations**: The `bind` and `force` operations in the `F` and `U` rows implement monadic behavior for effect handling.
3. **Product/Union Types**: The `×` and `+` rows define tuple and sum type operations with explicit case analysis.
4. **Error Propagation**: The ErrBot and StkStrict sections formalize error handling through type refinement and strictness annotations.
### Interpretation
This document formalizes a type system with:
1. **Type Casting Rules**: Ensuring safe upcasts (`A ⊆ A'`) and downcasts (`B' ⊆ B`) through logical implications.
2. **Effect Handling**: Using monadic operations (`bind`, `force`) to manage side effects and errors.
3. **Error Handling**: Differentiating between recoverable errors (`ErrBot`) and strict error propagation (`StkStrict`).
4. **Type Theory Foundations**: Employing dependent types (`π`, `λ`) and case analysis for algebraic data types.
The specifications appear to implement a **graded type system** with:
- **Bounded Casting**: Restricting casts to subtypes (`A ⊆ A'`)
- **Error Annotations**: Explicit error handling through type refinements
- **Strictness Control**: Differentiating between lazy (`U`) and strict (`F`) evaluation contexts
The document likely serves as a formal verification of a programming language's type system, ensuring type safety while allowing controlled type casting and error handling.