|
| 1 | += Julia the Viper Type System Specification (V2 Draft) |
| 2 | +:version: 2.0.0-draft |
| 3 | +:date: 2026-04-16 |
| 4 | + |
| 5 | +SPDX-License-Identifier: PMPL-1.0-or-later |
| 6 | +Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) |
| 7 | + |
| 8 | +== 0. Design Goals |
| 9 | + |
| 10 | +This document defines Version 2 of the Julia the Viper (JtV) type system. |
| 11 | + |
| 12 | +Goals: |
| 13 | + |
| 14 | +* Preserve Harvard separation between Data and Control. |
| 15 | +* Ensure Data fragment is statically total. |
| 16 | +* Introduce Safe Control fragment (S). |
| 17 | +* Keep Control fragment Turing-complete. |
| 18 | +* Add Echo typing layer without interfering with value types. |
| 19 | + |
| 20 | +== 1. Static Axes |
| 21 | + |
| 22 | +JtV typing operates across four orthogonal axes: |
| 23 | + |
| 24 | +1. Value typing: Γ ⊢ e : τ |
| 25 | +2. Fragment typing: |
| 26 | + * Γ ⊢_D e : τ |
| 27 | + * Γ ⊢_S s : () |
| 28 | + * Γ ⊢_C s : () |
| 29 | +3. Effect classification: |
| 30 | + * Total ⊂ Pure ⊂ Impure |
| 31 | +4. Echo classification: |
| 32 | + * EchoSafe | EchoNeutral | EchoBreaking |
| 33 | + |
| 34 | +== 2. Type Language |
| 35 | + |
| 36 | +---- |
| 37 | +τ ::= Int | Float | Rational | Complex |
| 38 | + | Hex | Binary |
| 39 | + | Symbolic |
| 40 | + | Bool |
| 41 | + | String |
| 42 | + | Unit |
| 43 | + | List[τ] |
| 44 | + | (τ₁, …, τₙ) |
| 45 | + | (τ₁, …, τₙ) → τᵣ |
| 46 | + | Any |
| 47 | +---- |
| 48 | + |
| 49 | +Echo is NOT part of τ in V2. |
| 50 | + |
| 51 | +== 3. Fragment Hierarchy |
| 52 | + |
| 53 | +D ⊂ S ⊂ C |
| 54 | + |
| 55 | +* D = Data (total) |
| 56 | +* S = Safe Control (total by construction) |
| 57 | +* C = Full Control (Turing-complete) |
| 58 | + |
| 59 | +== 4. Data Typing |
| 60 | + |
| 61 | +Examples: |
| 62 | + |
| 63 | +---- |
| 64 | +Γ ⊢_D n : Int |
| 65 | +Γ ⊢_D e₁ + e₂ : widen(τ₁, τ₂) |
| 66 | +Γ ⊢_D -e : τ |
| 67 | +---- |
| 68 | + |
| 69 | +No loops, no recursion, no effects. |
| 70 | + |
| 71 | +== 5. Safe Control Fragment (S) |
| 72 | + |
| 73 | +Allowed: |
| 74 | + |
| 75 | +* let from Data |
| 76 | +* sequencing |
| 77 | +* if with Data guards |
| 78 | +* bounded for loops |
| 79 | +* calls to @total functions |
| 80 | + |
| 81 | +Forbidden: |
| 82 | + |
| 83 | +* while |
| 84 | +* unrestricted recursion |
| 85 | +* I/O |
| 86 | +* impure calls |
| 87 | + |
| 88 | +== 6. Safe Loop Rule |
| 89 | + |
| 90 | +---- |
| 91 | +Γ ⊢_D start : Int |
| 92 | +Γ ⊢_D end : Int |
| 93 | +Γ, x:Int ⊢_S body : () |
| 94 | +-------------------------------- |
| 95 | +Γ ⊢_S for x in start..end { body } : () |
| 96 | +---- |
| 97 | +
|
| 98 | +== 7. Effects |
| 99 | +
|
| 100 | +---- |
| 101 | +Total ⊂ Pure ⊂ Impure |
| 102 | +---- |
| 103 | +
|
| 104 | +@total functions must check entirely in S. |
| 105 | +
|
| 106 | +== 8. Echo Layer |
| 107 | +
|
| 108 | +---- |
| 109 | +Echo ::= EchoSafe | EchoNeutral | EchoBreaking |
| 110 | +---- |
| 111 | +
|
| 112 | +Example: |
| 113 | +
|
| 114 | +---- |
| 115 | +Γ ⊢ e₁ + e₂ : EchoSafe |
| 116 | +Γ ⊢ x = e : EchoBreaking |
| 117 | +---- |
| 118 | +
|
| 119 | +Echo does not affect core typing. |
| 120 | +
|
| 121 | +== 9. Reverse Blocks |
| 122 | +
|
| 123 | +---- |
| 124 | +All statements must be invertible AND not EchoBreaking. |
| 125 | +---- |
| 126 | +
|
| 127 | +== 10. Guarantees |
| 128 | +
|
| 129 | +* Data always terminates |
| 130 | +* Safe Control always terminates |
| 131 | +* Control may diverge |
| 132 | +* Halting boundary is syntactic and decidable |
| 133 | +* Echo does not interfere with typing |
| 134 | +
|
| 135 | +== 11. Summary |
| 136 | +
|
| 137 | +JtV V2 introduces a safe computational island: |
| 138 | +
|
| 139 | +Data (total) ⊂ Safe Control (total) ⊂ Control (general) |
| 140 | +
|
| 141 | +This enables: |
| 142 | +
|
| 143 | +* static termination guarantees |
| 144 | +* explicit boundary of undecidability |
| 145 | +* extensibility via echo typing |
0 commit comments