Add Bool type

This commit is contained in:
Gabriel Gonzalez 2016-09-07 19:29:32 -07:00
parent 857f008931
commit b74bd78f17
3 changed files with 10 additions and 0 deletions

View File

@ -159,6 +159,8 @@ data Expr a
| Lets [Let a] (Expr a)
-- | > Annot x t ~ x : t
| Annot (Expr a) (Expr a)
-- | > Bool ~ Bool
| Bool
-- | > Natural ~ Natural
| Natural
-- | > NaturalLit n ~ +n
@ -223,6 +225,7 @@ instance Monad Expr where
return (x, t >>= k)
return (Let f as' (r >>= k))
Annot x t >>= k = Annot (x >>= k) (t >>= k)
Bool >>= _ = Bool
Natural >>= _ = Natural
NaturalLit n >>= _ = NaturalLit n
NaturalFold >>= _ = NaturalFold
@ -291,6 +294,7 @@ instance Eq a => Eq (Expr a) where
go (App fL aL) (App fR aR) = do
b1 <- go fL fR
if b1 then go aL aR else return False
go Bool Bool = return True
go Natural Natural = return True
go (NaturalLit x) (NaturalLit y) = return (x == y)
go Integer Integer = return True
@ -387,6 +391,7 @@ instance Buildable a => Buildable (Expr a)
go True False x
<> " : "
<> go False False t
Bool -> "Bool"
Natural -> "Natural"
NaturalLit n -> "+" <> build (show n)
NaturalFold -> "Natural/fold"
@ -686,6 +691,8 @@ typeWith ctx e@(Annot x t ) = do
let nf_t = normalize t
let nf_t' = normalize t'
Left (TypeError ctx e (AnnotMismatch nf_t nf_t'))
typeWith _ Bool = do
return (Const Star)
typeWith _ Natural = do
return (Const Star)
typeWith _ (NaturalLit _ ) = do

View File

@ -70,6 +70,7 @@ tokens :-
"->" | "→" { \_ -> yield Arrow }
"\/" | "|~|" | "forall" | "∀" | "Π" { \_ -> yield Pi }
"\" | "λ" { \_ -> yield Lambda }
"Bool" { \_ -> yield Bool }
"Natural" { \_ -> yield Natural }
"Natural/fold" { \_ -> yield NaturalFold }
"Integer" { \_ -> yield Integer }
@ -219,6 +220,7 @@ data Token
| Arrow
| Lambda
| Pi
| Bool
| Natural
| NaturalLit Natural
| NaturalFold

View File

@ -166,6 +166,7 @@ expr = mdo
( (Var <$> label)
<|> (match Lexer.Type *> pure (Const Star))
<|> (match Lexer.Box *> pure (Const Box))
<|> (match Lexer.Bool *> pure Bool)
<|> (match Lexer.Natural *> pure Natural)
<|> (match Lexer.NaturalFold *> pure NaturalFold)
<|> (match Lexer.Integer *> pure Integer)