In a previous question, I had types for a toy language
data Type : Set where
Nat : Type
Prp : Type
I thought about interpreting them by using a disjoint union
Type → Set ⊎ Set₁
, but thought level lifiting would be best
and was helped to obtain
⟦_⟧ₜ : Type → Set₁
⟦ Nat ⟧ₜ = Lift ℕ
⟦ Prp ⟧ₜ = Set
Now suppose my toy language has variables and expressions
data Variable : Type → Set where
x y : ∀ {t} → Variable t
data Expr : Type → Set₁ where
Var : ∀ {t} (v : Variable t) → Expr t -- varaible symbols
: ℕ → Expr Nat -- constant symbols
: Set → Expr Prp
_+_ : (m n : Expr Nat) → Expr Nat -- binary function symbol
_≈_ : (e f : Expr Nat) → Expr Prp -- binary relation symbol
Then semantics of expressions,
State = ∀ {t} → Variable t → ⟦ t ⟧ₜ
⟦_⟧ₑ : ∀ {t} → Expr t → State → ⟦ t ⟧ₜ
⟦_⟧ₑ (Var v) σ = σ v
⟦_⟧ₑ ( q) σ = lift q
⟦_⟧ₑ ( p) σ = p
⟦_⟧ₑ (e + e₁) σ = lift $ lower (⟦ e ⟧ₑ σ) +ℕ lower (⟦ e₁ ⟧ₑ σ)
⟦_⟧ₑ (e ≈ e₁) σ = lift (lower (⟦ e ⟧ₑ σ)) ≡ lift (lower (⟦ e₁ ⟧ₑ σ))
I kind of get that in-general lift (lower x) ≠ x
due to 'level refreshing' due to lift
,
but still why cannot the last line simply be ⟦ e ⟧ₑ σ ≡ ⟦ e₁ ⟧ₑ σ
?
I must admit that this is my first time using Lift
and sadly did not find a tutorial/explanation on it ---besides the idea that it embeds small types into large types, as indicated by its definition.
Since I've everything laid out, let me make a rather particular query.
With the standard/derived equalities,
-- no quick `deriving Eq' mechanism, yet.
postulate _≟ₜ_ : Decidable {A = Type} _≡_
postulate _≟ᵥ_ : ∀ {t s} → Variable t → Variable s → Bool
I can defined textual substitution over expressions,
_[_/_] : ∀ {s t} → Expr t → Variable s → Expr s → Expr t
_[_/_] {s} {t} (Var v) u e with s ≟ₜ t
Var v [ u / e ] | yes refl = if v ≟ᵥ u then e else Var v
Var v [ u / e ] | no ¬p = Var v
n [ v / e ] = n
p [ v / e ] = p
(E + F) [ v / e ] = E [ v / e ] + F [ v / e ]
(E ≈ F) [ v / e ] = E [ v / e ] ≈ F [ v / e ]
Now is the issue of variable occurrences within expressions.
_not-occurs-in₀_ : ∀ {t} → Variable t → Expr t → Set₁
v not-occurs-in₀ E = ∀ {e} → E [ v / e ] ≡ E
_not-occurs-in₁_ : ∀ {t} → Variable t → Expr t → Set₁
v not-occurs-in₁ E = ∀ {e} {σ : State} → ⟦ E [ v / e ] ⟧ₑ σ ≡ ⟦ E ⟧ₑ σ
I've had trouble using either definition. In particular, I could not even define one in terms of the other. Any help on this would be appreciated!
After some digging around, I tried
levelOf : Type → Level
levelOf Nat = zero
levelOf Prp = suc zero
New⟦_⟧ₜ : (t : Type) → Set (levelOf t)
New⟦ Nat ⟧ₜ = ℕ
New⟦ Prp ⟧ₜ = Set
However, now I get Setω
errors for the definition of State
above! That is,
-- works fine if i use the risky {-# OPTIONS --type-in-type #-}
NState = {t : Type} → Variable t → New⟦ {!t!} ⟧ₜ
As far as I know, such an error occurs, roughly, when one has an assignment of levels to universes.
What shenanigans am I unsconsciously doing to get this trouble?