floating-levels/theories/typing.v
2025-05-29 16:35:49 -04:00

67 lines
1.7 KiB
Coq
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Require Import Autosubst2.syntax List.
Reserved Notation "Γ ⊢ a ;; ∈ A" (at level 70).
Definition get_level a :=
match a with
| Fixed =>
| Floating =>
end.
Inductive lookup {A} : nat -> list A -> A -> Prop :=
| here A Γ : lookup 0 (cons A Γ) A
| there i Γ A B :
lookup i Γ A ->
lookup (S i) (cons B Γ) A.
Definition ctx := list (Level * Ty).
Definition squash a :=
match a with
| Fixed => false
| Floating => true
end.
Fixpoint fixed_ctx (Γ : ctx) :=
match Γ with
| nil => nil
| (a, _) :: Γ => squash a :: fixed_ctx Γ
end.
(* false <= true *)
(* A term is liftable if it remains well-typed raising the levels of the floating levels to the current level *)
Fixpoint liftable Φ (a : Tm) :=
match a with
| VarTm i => lookup i Φ false
| FlApp a b => liftable Φ a /\ liftable Φ b
| App a b => liftable Φ a
| FlAbs a => liftable (false :: Φ) a
| Abs a => liftable (false :: Φ) a
end.
Inductive Wt (Γ : ctx) : Tm -> bool -> Ty -> Prop :=
| T_Var i 0 A :
Bool.le (get_level 0) ->
lookup i Γ (0, A) ->
Γ VarTm i ;; A
| T_FlApp a b A B :
Γ b ;; FlFun A B ->
Γ a ;; A ->
Γ FlApp b a ;; B
| T_FlAbs a A B :
(Floating , A) :: Γ a ;; B ->
Γ FlAbs a ;; FlFun A B
| T_App 0 a b A B :
Γ b ;; Fun 0 A B ->
Γ a ;; 0 A ->
liftable (fixed_ctx Γ) a ->
Γ App b a ;; A
| T_Abs 0 b A B :
(Fixed 0, A) :: Γ b ;; B ->
Γ Abs b ;; Fun 0 A B
where "Γ ⊢ a ;; ∈ A" := (Wt Γ a A).