Files
iris/BidirTT/Context.lean
T

31 lines
781 B
Lean4
Raw Normal View History

2026-04-19 04:17:45 +00:00
import BidirTT.Value
namespace BidirTT
structure Cxt where
env : Env
types : List (Name × Val)
lvl : Lvl
deriving Inhabited
def Cxt.empty : Cxt := [], [], 0
def Cxt.bind (cxt : Cxt) (x : Name) (a : Val) : Cxt :=
{ env := .var cxt.lvl :: cxt.env
, types := (x, a) :: cxt.types
, lvl := cxt.lvl + 1 }
def Cxt.define (cxt : Cxt) (x : Name) (v a : Val) : Cxt :=
{ env := v :: cxt.env
, types := (x, a) :: cxt.types
, lvl := cxt.lvl + 1 }
private def lookupGo : Name List (Name × Val) Nat Option (Nat × Val)
| _, [], _ => none
| x, (y, a) :: rest, i => if x == y then some (i, a) else lookupGo x rest (i+1)
def Cxt.lookup (cxt : Cxt) (x : Name) : Option (Nat × Val) :=
lookupGo x cxt.types 0
end BidirTT