79 lines
2.6 KiB
Agda
79 lines
2.6 KiB
Agda
{-# OPTIONS --prop #-}
|
||
module Ahmed.Day1 where
|
||
|
||
open import Data.Empty
|
||
open import Data.Unit
|
||
open import Data.Bool
|
||
open import Data.Nat
|
||
open import Data.Fin
|
||
open import Data.Product
|
||
open import Relation.Nullary using (Dec; yes; no)
|
||
import Relation.Binary.PropositionalEquality as Eq
|
||
open Eq using (_≡_; refl; trans; sym; cong; cong-app)
|
||
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
|
||
|
||
data type : Set where
|
||
bool : type
|
||
_-→_ : type → type → type
|
||
|
||
data ctx : ℕ → Set where
|
||
nil : ctx zero
|
||
_,_ : ∀ {n} → ctx n → type → ctx (suc n)
|
||
|
||
data term : (n : ℕ) → Set where
|
||
`_ : ∀ {n} → (m : Fin n) → term n
|
||
true : ∀ {n} → term n
|
||
false : ∀ {n} → term n
|
||
λ[_]_ : ∀ {n} → (τ₁ : type) (e : term (suc n)) → term n
|
||
_∙_ : ∀ {n} → term n → term n → term n
|
||
|
||
postulate
|
||
lookup : ∀ {n} → Fin n → ctx n → type
|
||
-- lookup {n} Γ
|
||
|
||
data typing : ∀ {n} {Γ : ctx n} → term n → type → Set where
|
||
`_ : ∀ {n Γ τ} → (m : Fin n) → lookup m Γ ≡ τ → typing {n} {Γ} (` m) τ
|
||
true : ∀ {n Γ} → typing {n} {Γ} true bool
|
||
false : ∀ {n Γ} → typing {n} {Γ} false bool
|
||
|
||
data is-value : ∀ {n} → (e : term n) → Set where
|
||
true : ∀ {n} → is-value {n} true
|
||
false : ∀ {n} → is-value {n} false
|
||
λ[_]_ : ∀ {n} → (τ : type) → (e : term (suc n)) → is-value {n} (λ[ τ ] e)
|
||
|
||
value = ∀ {n} → Σ (term n) (is-value)
|
||
|
||
lift-term : ∀ {n} → term n → term (suc n)
|
||
lift-term {n} (` m) = ` (suc m)
|
||
lift-term {n} true = true
|
||
lift-term {n} false = false
|
||
lift-term {n} (λ[ τ₁ ] e) = λ[ τ₁ ] lift-term e
|
||
lift-term {n} (e ∙ e₁) = lift-term e ∙ lift-term e₁
|
||
|
||
subst : ∀ {n} → (e : term (suc n)) → (v : term n) → term n
|
||
subst {n} (` zero) v = v
|
||
subst {n} (` suc m) v = ` m
|
||
subst true v = true
|
||
subst false v = false
|
||
subst (λ[ τ ] e) v = λ[ τ ] subst e (lift-term v)
|
||
subst (e₁ ∙ e₂) v = subst e₁ v ∙ subst e₂ v
|
||
|
||
data step : ∀ {n} → term n → term n → Set where
|
||
β-step : ∀ {n τ e e₂} → step {n} ((λ[ τ ] e) ∙ e₂) (subst e e₂)
|
||
|
||
-- irreducible : ∀ {n} → (e : term) → ∃[ e' ] mapsto e'
|
||
|
||
-- type-soundness : ∀ {e τ} →
|
||
|
||
value-relation : ∀ {n} → (τ : type) → (e : term n) → Set
|
||
expr-relation : ∀ {n} → (τ : type) → (e : term n) → Set
|
||
|
||
value-relation bool true = ⊤
|
||
value-relation bool false = ⊤
|
||
value-relation (τ₁ -→ τ₂) ((λ[ τ ] e) ∙ v) = expr-relation τ₂ {! !}
|
||
value-relation _ _ = ⊥
|
||
|
||
expr-relation {n} τ e = {! !}
|
||
|
||
semantic-soundness : ∀ {n} (Γ : ctx n) → (τ : type) → (e : term n) → Set
|
||
-- semantic-soundness {n} Γ τ e = (γ : substitution n) → expr-relation τ {! !} |