mcenv / mce

A programming environment for Minecraft
MIT License
15 stars 0 forks source link

Compile-time modalities #120

Open intsuc opened 2 years ago

intsuc commented 2 years ago

Let π’ž be a compile-time modality. All types are indexed by either π’ž or Β¬π’ž.

The constructor 𝒸 - are hidden from the surface syntax. If a : Ξ±, then a ⇐ (Ξ± @ π’ž) elaborates to 𝒸 a by subtyping coercion. 𝒸 a works as a marker to normalize a without type-directedness.

Definitions are indexed by compile-time modalities as follows:

{builtin}
def + [a : (int @ π’œ), b : (int @ ℬ)] : (int @ (π’œ ∧ ℬ)) ≔ _

Compile-time modalities can be elided as Rust's lifetime elision. The following definition elaborates to the above definition.

{builtin}
def + [a : int, b : int] : int ≔ _

For example, the following definitional equalities hold:

((𝒸 1) + (𝒸 2)) : (int @ π’ž) = (𝒸 3) : (int @ π’ž)
((𝒸 1) + 2) : (int @ Β¬π’ž) = (1 + 2) : (int @ Β¬π’ž)
(1 + (𝒸 2)) : (int @ Β¬π’ž) = (1 + 2) : (int @ Β¬π’ž)
(1 + 2) : (int @ Β¬π’ž) = (1 + 2) : (int @ Β¬π’ž)

Runtime-only definitions are represented by Β¬π’ž as follows:

def seed [] : (int @ Β¬π’ž)

A type with π’ž must not contain types with Β¬π’ž. Since its inhabitant cannot evaluate to its canonical form, the following type is ill-formed:

(list (int @ Β¬π’ž) @ π’ž)