Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KonjacSource committed Oct 19, 2024
1 parent 2c5c373 commit 21106d4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Examples/Bool.shitt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data Bool : U where
| true : ...
| false : ...

fun not (_ : Bool) : Bool
| true = false
| false = true

fun and (_ _ : Bool) : Bool
| true true = true
| _ _ = false

fun or (_ _ : Bool) : Bool
| false false = false
| _ _ = true
20 changes: 20 additions & 0 deletions Examples/Exp.shitt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#load "Nat.shitt"
#load "Bool.shitt"

data Exp : (_ : U) -> U where
| nat : (_ : N) -> ... N
| bool : (_ : Bool) -> ... Bool
| andF : ... (Bool -> Bool -> Bool)
| notF : ... (Bool -> Bool)
| addF : ... (N -> N -> N)
| app : {a b : U} (f : Exp (a -> b)) (arg : Exp a) -> ... b

axiom partial fun sorry {A: U} : A

fun eval {A: U} (e : Exp A) : A
| nat x = x
| bool b = b
| andF = and
| notF = not
| addF = add
| app f x = eval f (eval x)
11 changes: 11 additions & 0 deletions Examples/Id.shitt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data Id {A : U} : (x y : A) -> U where
| refl : (t : A) -> ... t t

fun sym {A : U} {x y : A} (p : Id x y) : Id y x where
| (refl _) = refl _

fun trans {A : U} {x y z : A} (_ : Id x y) (_ : Id y z) : Id x z where
| (refl _) (refl _) = refl _

fun cong {A B : U} {x y : A} (f : A -> B) (p : Id x y) : Id (f x) (f y) where
| f (refl _) = refl _
25 changes: 25 additions & 0 deletions Examples/Nat.shitt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#load "Id.shitt"

data N : U where
| zero : ...
| succ : (pre : N) -> ...

fun add (m n : N) : N where
| zero n = n
| (succ m) n = succ (add m n)

fun addAssoc (x y z : N) : Id (add (add x y) z) (add x (add y z)) where
| zero y z = refl _
| (succ x) y z = cong succ (addAssoc x y z)

fun addIdR (x : N) : Id (add x zero) x where
| zero = refl _
| (succ x) = cong succ (addIdR x)

fun addSucc (x y : N) : Id (add (succ x) y) (add x (succ y)) where
| zero y = refl _
| (succ x) y = cong succ (addSucc x y)

fun addComm (x y : N) : Id (add x y) (add y x) where
| zero y = sym (addIdR _)
| (succ x) y = trans (cong succ (addComm x y)) (addSucc y x)
6 changes: 3 additions & 3 deletions src/ShiTT/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unifySp ctx sp sp' = case (sp, sp') of
_ -> throwIO UnifyError

unify :: Context -> Value -> Value -> IO ()
unify ctx (force ctx -> t) (force ctx -> u) = -- trace ("UNIFYING: " ++ show t ++ " WITH " ++ show u) $
unify ctx (refresh ctx -> t) (refresh ctx -> u) = -- trace ("UNIFYING: " ++ show t ++ " WITH " ++ show u) $
case (t, u) of
---
(VU, VU) -> pure ()
Expand All @@ -88,9 +88,9 @@ unify ctx (force ctx -> t) (force ctx -> u) = -- trace ("UNIFYING: " ++ show t +
unify (ctx <: freeVar x') (t @ x := VVar x') (vApp ctx t' (VVar x') i)
---
(VPi x i a b, VPi x' i' a' b') | i == i' -> do
let y = freshName ctx x
let fre = freshName ctx x
unify ctx a a'
unify (ctx <: freeVar x') (b @ x := VVar y) (b' @ x' := VVar y)
unify (ctx <: freeVar fre) (b @ x := VVar fre) (b' @ x' := VVar fre)
---
(VCon con sp, VCon con' sp') | con == con' -> unifySp ctx sp sp'
---
Expand Down
13 changes: 10 additions & 3 deletions src/ShiTT/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ instance Show Value where
VLam x Expl b -> inParen $ "lambda " ++ x ++ ". " ++ pp True (b @ x := VVar x)
VLam x Impl b -> inParen $ "lambda {" ++ x ++ "}. " ++ pp True (b @ x := VVar x)
VRig x sp -> if null sp then remove_infix x else inParen $ x ++ ppSp sp
VCon x sp -> {-"!con!" ++ -}pp is_top (VRig x sp)
VCon x sp -> pp is_top (VRig x sp)
VFlex m sp -> pp is_top (VRig ('?':show m) sp)
VFunc x sp -> {- "!fun!" ++ -}pp is_top (VRig x.funName sp)
VPatVar x sp -> {- "!pat!" ++ -}pp is_top (VRig x sp)
VFunc x sp -> pp is_top (VRig x.funName sp)
VPatVar x sp -> pp is_top (VRig x sp)
VPi x Expl t b -> inParen $ "Pi (" ++ x ++ ":" ++ pp True t ++ "). " ++ pp True (b @ x := VVar x)
VPi x Impl t b -> inParen $ "Pi {" ++ x ++ ":" ++ pp True t ++ "}. " ++ pp True (b @ x := VVar x)
VU -> "U"
where paren x = '(' : x ++ ")"
inParen x = if is_top then x else paren x

-- For debug
-- deriving instance Show Value
-- instance Show Closure where
-- show (Closure _ b) = show b

instance Show Context where
show ctx = "\n- env:" ++ show ctx.env ++ "\n- typ:" ++ show ctx.types ++ "\n- sig:" ++ show ctx.decls

Expand Down Expand Up @@ -80,6 +85,8 @@ eval ctx@(env -> env) = \case
Meta m -> vMeta m
---
PatVar x -> case M.lookup x env of
Just (VPatVar y [])
| y /= x -> eval ctx (PatVar y)
Just v -> v
Nothing
| head x == '*' -> VPatVar x []
Expand Down

0 comments on commit 21106d4

Please sign in to comment.