summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/LambdaCube/Compiler/Core.hs45
-rw-r--r--src/LambdaCube/Compiler/Infer.hs4
-rw-r--r--src/LambdaCube/Compiler/InferMonad.hs2
3 files changed, 10 insertions, 41 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs
index c349f59d..27bd6372 100644
--- a/src/LambdaCube/Compiler/Core.hs
+++ b/src/LambdaCube/Compiler/Core.hs
@@ -176,7 +176,7 @@ pattern TTyCon s t a <- TyCon (TyConName s _ t _ _) a
176pattern TTyCon0 s <- TyCon (TyConName s _ _ _ _) [] 176pattern TTyCon0 s <- TyCon (TyConName s _ _ _ _) []
177 177
178tTyCon s t a cs = TyCon (TyConName s (error "todo: inum") t (map ((,) (error "tTyCon")) cs) $ CaseFunName (error "TTyCon-A") (error "TTyCon-B") $ length a) a 178tTyCon s t a cs = TyCon (TyConName s (error "todo: inum") t (map ((,) (error "tTyCon")) cs) $ CaseFunName (error "TTyCon-A") (error "TTyCon-B") $ length a) a
179tTyCon0 s cs = Closed $ TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) [] 179tTyCon0 s cs = TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) []
180 180
181pattern a :~> b = Pi Visible a b 181pattern a :~> b = Pi Visible a b
182 182
@@ -197,7 +197,7 @@ pattern Empty s <- TyCon (TyConName FEmpty _ _ _ _) [HString{-hnf?-} s]
197 where Empty s = TyCon (TyConName FEmpty (error "todo: inum2_") (TString :~> TType) (error "todo: tcn cons 3_") $ error "Empty") [HString s] 197 where Empty s = TyCon (TyConName FEmpty (error "todo: inum2_") (TString :~> TType) (error "todo: tcn cons 3_") $ error "Empty") [HString s]
198 198
199pattern TT <- ConN _ _ 199pattern TT <- ConN _ _
200 where TT = Closed (tCon FTT 0 Unit []) 200 where TT = tCon FTT 0 Unit []
201 201
202pattern CUnit <- ConN FCUnit _ 202pattern CUnit <- ConN FCUnit _
203 where CUnit = tCon FCUnit 0 TConstraint [] 203 where CUnit = tCon FCUnit 0 TConstraint []
@@ -221,23 +221,23 @@ pattern HString a = HLit (LString a)
221 221
222pattern EBool a <- (getEBool -> Just a) 222pattern EBool a <- (getEBool -> Just a)
223 where EBool = \case 223 where EBool = \case
224 False -> Closed $ tCon FFalse 0 TBool [] 224 False -> tCon FFalse 0 TBool []
225 True -> Closed $ tCon FTrue 1 TBool [] 225 True -> tCon FTrue 1 TBool []
226 226
227getEBool (hnf -> ConN FFalse _) = Just False 227getEBool (hnf -> ConN FFalse _) = Just False
228getEBool (hnf -> ConN FTrue _) = Just True 228getEBool (hnf -> ConN FTrue _) = Just True
229getEBool _ = Nothing 229getEBool _ = Nothing
230 230
231pattern ENat n <- (fromNatE -> Just n) 231pattern ENat n <- (fromNatE -> Just n)
232 where ENat 0 = Closed $ tCon FZero 0 TNat [] 232 where ENat 0 = tCon FZero 0 TNat []
233 ENat n | n > 0 = Closed $ tCon FSucc 1 (TNat :~> TNat) [ENat (n-1)] 233 ENat n | n > 0 = tCon FSucc 1 (TNat :~> TNat) [ENat (n-1)]
234 234
235fromNatE :: Exp -> Maybe Int 235fromNatE :: Exp -> Maybe Int
236fromNatE (hnf -> ConN FZero _) = Just 0 236fromNatE (hnf -> ConN FZero _) = Just 0
237fromNatE (hnf -> ConN FSucc (n:_)) = succ <$> fromNatE n 237fromNatE (hnf -> ConN FSucc (n:_)) = succ <$> fromNatE n
238fromNatE _ = Nothing 238fromNatE _ = Nothing
239 239
240mkOrdering x = Closed $ case x of 240mkOrdering x = case x of
241 LT -> tCon FLT 0 TOrdering [] 241 LT -> tCon FLT 0 TOrdering []
242 EQ -> tCon FEQ 1 TOrdering [] 242 EQ -> tCon FEQ 1 TOrdering []
243 GT -> tCon FGT 2 TOrdering [] 243 GT -> tCon FGT 2 TOrdering []
@@ -385,38 +385,7 @@ instance HasFreeVars Neutral where
385varType' :: Int -> [Exp] -> Exp 385varType' :: Int -> [Exp] -> Exp
386varType' i vs = vs !! i 386varType' i vs = vs !! i
387 387
388pattern Closed :: () => ClosedExp a => a -> a
389pattern Closed a <- a where Closed a = closedExp a
390
391-- TODO: remove?
392class ClosedExp a where
393 closedExp :: a -> a
394
395instance ClosedExp ExpType where
396 closedExp (ET a b) = ET (closedExp a) (closedExp b)
397
398instance ClosedExp Exp where
399 closedExp = \case
400 Lam_ _ c -> Lam_ mempty c
401 Pi_ _ a b c -> Pi_ mempty a (closedExp b) c
402 Con_ _ a b c -> Con_ mempty a b (closedExp <$> c)
403 TyCon_ _ a b -> TyCon_ mempty a (closedExp <$> b)
404 e@TType_{} -> e
405 e@ELit{} -> e
406 Neut a -> Neut $ closedExp a
407 Let a b -> Let_ mempty a b
408 RHS a -> RHS (closedExp a)
409
410instance ClosedExp Neutral where
411 closedExp = \case
412 x@Var_{} -> error "impossible"
413 CaseFun__ _ a as n -> CaseFun__ mempty a (closedExp <$> as) (closedExp n)
414 TyCaseFun__ _ a as n -> TyCaseFun__ mempty a (closedExp <$> as) (closedExp n)
415 App__ _ a b -> App__ mempty (closedExp a) (closedExp b)
416 Fun_ _ f x y -> Fun_ mempty f (closedExp <$> x) y
417
418-------------------------------------------------------------------------------- pretty print 388-------------------------------------------------------------------------------- pretty print
419-- todo: do this via conversion to SExp?
420 389
421instance PShow Exp where 390instance PShow Exp where
422 pShow = mkDoc (False, False) 391 pShow = mkDoc (False, False)
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index 999f09d5..3eaae43b 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -562,10 +562,10 @@ handleStmt = \case
562 stmt -> error $ "handleStmt: " ++ ppShow stmt 562 stmt -> error $ "handleStmt: " ++ ppShow stmt
563 563
564inferTerm :: Monad m => SIName -> SExp2 -> IM m ExpType 564inferTerm :: Monad m => SIName -> SExp2 -> IM m ExpType
565inferTerm sn t = fmap closedExp $ recheck sn EGlobal . replaceMetas (lamPi Hidden) =<< inferN EGlobal t 565inferTerm sn t = recheck sn EGlobal . replaceMetas (lamPi Hidden) =<< inferN EGlobal t
566 566
567inferType :: Monad m => SIName -> SExp2 -> IM m Type 567inferType :: Monad m => SIName -> SExp2 -> IM m Type
568inferType sn t = fmap (closedExp . expr) 568inferType sn t = fmap expr
569 $ recheck sn EGlobal . flip ET TType . replaceMetas (Pi Hidden) . fmap expr 569 $ recheck sn EGlobal . flip ET TType . replaceMetas (Pi Hidden) . fmap expr
570 =<< inferN (CheckType_ (sourceInfo sn) TType EGlobal) t 570 =<< inferN (CheckType_ (sourceInfo sn) TType EGlobal) t
571 571
diff --git a/src/LambdaCube/Compiler/InferMonad.hs b/src/LambdaCube/Compiler/InferMonad.hs
index 26f0e7eb..3e0aa980 100644
--- a/src/LambdaCube/Compiler/InferMonad.hs
+++ b/src/LambdaCube/Compiler/InferMonad.hs
@@ -146,7 +146,7 @@ addToEnv sn@(SIName si s) (ET x t) = do
146 tell [IType sn t] 146 tell [IType sn t]
147 v <- asks $ Map.lookup s . snd 147 v <- asks $ Map.lookup s . snd
148 case v of 148 case v of
149 Nothing -> return $ Map.singleton s (closedExp x, closedExp t, si) 149 Nothing -> return $ Map.singleton s (x, t, si)
150 Just (_, _, si') -> throwError' $ ERedefined s si si' 150 Just (_, _, si') -> throwError' $ ERedefined s si si'
151 151
152 152