Files
iris/BidirTT/Context.lean
T

31 lines
788 B
Lean4
Raw 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.
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 := .neu (.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