Preliminary work on data and holes

This commit is contained in:
2024-07-06 14:23:41 -04:00
parent b9f921ab3b
commit 46ddbc1f91
17 changed files with 311 additions and 169 deletions

View File

@@ -2,43 +2,10 @@ module Lib.TopContext
import Data.String
import Lib.TT
import Data.IORef
public export
data Def = Axiom | TCon (List String) | DCon Nat | Fn Tm
Show Def where
show Axiom = "axiom"
show (TCon strs) = "TCon \{show strs}"
show (DCon k) = "DCon \{show k}"
show (Fn t) = "Fn \{show t}"
||| entry in the top level context
public export
record TopEntry where
constructor MkEntry
name : String
type : Tm
def : Def
-- FIXME snoc
export
Show TopEntry where
show (MkEntry name type def) = "\{name} : \{show type} := \{show def}"
||| Top level context.
||| Most of the reason this is separate is to have a different type
||| `Def` for the entries.
|||
||| The price is that we have names in addition to levels. Do we want to
||| expand these during conversion?
public export
record TopContext where
constructor MkTop
-- We'll add a map later?
defs : List TopEntry
-- I want unique ids, to be able to lookup, update, and a Ref so
-- I don't need good Context discipline. (I seem to have made mistakes already.)
export
lookup : String -> TopContext -> Maybe TopEntry
@@ -51,15 +18,15 @@ lookup nm top = go top.defs
-- Maybe pretty print?
export
Show TopContext where
show (MkTop defs) = "\nContext:\n [\{ joinBy "\n" $ map show defs}]"
show (MkTop defs metas) = "\nContext:\n [\{ joinBy "\n" $ map show defs}]"
public export
empty : TopContext
empty = MkTop []
empty : HasIO m => m TopContext
empty = pure $ MkTop [] !(newIORef (MC [] 0))
public export
claim : TopContext -> String -> Tm -> TopContext
claim tc name ty = { defs $= (MkEntry name ty Axiom ::) } tc
claim : String -> Tm -> TopContext -> TopContext
claim name ty = { defs $= (MkEntry name ty Axiom ::) }
-- TODO update existing, throw, etc.