Skip to content

Commit

Permalink
Define substitutions on core expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xd34df00d committed Sep 24, 2020
1 parent ab83b4e commit 7b77365
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions agda/Core/Syntax.agda
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module Core.Syntax where

open import Agda.Builtin.Bool
open import Agda.Builtin.List public
open import Agda.Builtin.String
open import Data.Nat.Base public
open import Data.Bool using (if_then_else_ ; _∨_)
open import Data.Fin public using (Fin)
open import Data.Nat.Base public
open import Data.Product public using (_×_)
open import Data.Product using (_,_)
open import Data.Vec.Base
Expand All @@ -17,6 +19,11 @@ record Var : Set where
field
var : String

open Var

var-eq : Var Var Bool
var-eq x₁ x₂ = primStringEquality (var x₁) (var x₂)

ADTCons : Set
CaseBranches : Set

Expand Down Expand Up @@ -63,7 +70,37 @@ variable
Γ Γ' Δ : Ctx
x x' x₁ x₂ y ν ν₁ ν₂ : Var
τ τ' τ₁ τ₂ τ₁' τ₂' τᵢ τⱼ σ : CExpr
ε ε' ε₁ ε₂ ε₁' ε₂' : CExpr
ε ε' ε₁ ε₂ ε₃ ε₁' ε₂' ϖ : CExpr
b b' b₁ b₂ : CExpr
n :
s : Sort
s s₁ s₂ : Sort


substCons : Var CExpr ADTCons n ADTCons n

infix 30 [_↦_]_
[_↦_]_ : Var CExpr CExpr CExpr
[ x ↦ ε ] CVar var = if var-eq x var then ε else CVar var
[ x ↦ ε ] CSort s = CSort s
[ x ↦ ε ] CPi var ε₁ ε₂ = let ε₁' = [ x ↦ ε ] ε₁
ε₂' = if var-eq x var then ε₂ else [ x ↦ ε ] ε₂
in CPi var ε₁' ε₂'
[ x ↦ ε ] CLam var ε₁ ε₂ = let ε₁' = [ x ↦ ε ] ε₁
ε₂' = if var-eq x var then ε₂ else [ x ↦ ε ] ε₂
in CLam var ε₁' ε₂'
[ x ↦ ε ] CApp ε₁ ε₂ = CApp ([ x ↦ ε ] ε₁) ([ x ↦ ε ] ε₂)
[ x ↦ ε ] Cunit = Cunit
[ x ↦ ε ] CUnit = CUnit
[ x ↦ ε ] CADT cons = CADT (substCons x ε cons)
[ x ↦ ε ] CCon idx ε' cons = CCon idx ([ x ↦ ε ] ε') (substCons x ε cons)
[ x ↦ ε ] CCase ε' branches = CCase ([ x ↦ ε ] ε') (go branches)
where
go : CaseBranches n CaseBranches n
go [] = []
go (b@(MkCaseBranch x' π body) ∷ bs) = let b = if var-eq x x' ∨ var-eq x π
then b
else MkCaseBranch x' π ([ x ↦ ε ] body)
in b ∷ go bs

substCons x ε [] = []
substCons x ε (con ∷ cons) = [ x ↦ ε ] con ∷ substCons x ε cons

0 comments on commit 7b77365

Please sign in to comment.