Fix implicit/explicit printing, various other issues

This commit is contained in:
2024-04-10 22:02:33 -07:00
parent 203159d1da
commit 3b1bd4aad1
7 changed files with 51 additions and 42 deletions

View File

@@ -8,22 +8,13 @@ import Data.String
import Lib.TT
import Syntax
record Context (n : Nat) (f : Nat) where
-- review this
env : Env f n -- Vect n (Val f)
types : List (String, Val f)
pos : SourcePos
extend : Context n f -> Val f -> Context (S n) f
extend ctx ty = { env := ty :: ctx.env } ctx
-- cribbed this, it avoids MonadError String m => everywhere
parameters {0 m : Type -> Type} {auto _ : MonadError String m}
infer : {f : Nat} -> Context n f -> Raw -> m (Tm n, Val f)
-- I think I'm hand-waving n here, probably need it in Context
check : {f : Nat} -> Context n f -> Raw -> Val f -> m (Tm n)
infer : {f : Nat} -> Context -> Raw -> m (Tm, Val)
check : {f : Nat} -> Context -> Raw -> Val -> m Tm
check ctx (RLam _ _ _) ty = ?ch_rhs
check ctx tm ty = do
@@ -35,10 +26,10 @@ parameters {0 m : Type -> Type} {auto _ : MonadError String m}
infer ctx (RVar nm) = go 0 ctx.types
where
go : Nat -> List (String, Val f) -> m (Tm n, Val f)
go : Nat -> List (String, Val) -> m (Tm, Val)
go i [] = throwError "\{show nm} not in scope"
-- REVIEW Local or Bnd (ezoo does not have both)
go i ((x, ty) :: xs) = if x == nm then pure $ (Bnd ?i_not_fin, ty)
go i ((x, ty) :: xs) = if x == nm then pure $ (Bnd i, ty)
else go (i + 1) xs

View File

@@ -3,7 +3,8 @@ module Lib.Prettier
import Data.String
import Data.Nat
-- A prettier printer, Wadler
-- A prettier printer, Philip Wadler
-- https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
||| `Doc` is a pretty printing document. Constructors are private, use
||| methods below. `Alt` in particular has some invariants on it, see paper

View File

@@ -1,3 +1,4 @@
-- I'm not sure this is related, or just a note to self (Presheaves on Porpoise)
-- maybe watch https://www.youtube.com/watch?v=3gef0_NFz8Q
-- or drop the indices for now.
@@ -133,24 +134,23 @@ nf env t = quote n (eval [] env t)
public export
conv : (lvl : Nat) -> Val -> Val -> Bool
data BD = Bound | Defined
-- data BD = Bound | Defined
-- public export
-- Types : Type
-- Types = List (Name, Lazy Val)
public export
Types : Type
Types = List (Name, Lazy Val)
-- REVIEW indices
public export
record Context where
constructor MkCtx
env : Env
types : List (String, Val)
pos : SourcePos
-- data Env : (tm : SnocList Name -> Type) -> SnocList Name -> Type where
env : Env -- Values in scope
types : List (String, Val) -- types and names in scope
-- bds : List BD -- bind or define
-- lvl = length types
pos : SourcePos -- the last SourcePos that we saw
-- Kovacs Small-TT has locals and globals, lets do that.
-- Still need to sort out the indices - one or two on env?
||| add a binding to environment
extend : { n : Nat} -> Context -> String -> Val -> Context
@@ -164,7 +164,7 @@ extend (MkCtx env types pos) name ty =
-- Is it ok to leaving them in there (if they pass checkType) as long as
-- we don't register the def if it fails checking?
-- shoot, I have another of these in Check.idr
-- shoot, I have another context in Check.idr
-- -- public export