diff options
-rw-r--r-- | src/LambdaCube/Compiler/Core.hs | 45 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/InferMonad.hs | 2 |
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 | |||
176 | pattern TTyCon0 s <- TyCon (TyConName s _ _ _ _) [] | 176 | pattern TTyCon0 s <- TyCon (TyConName s _ _ _ _) [] |
177 | 177 | ||
178 | tTyCon 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 | 178 | tTyCon 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 |
179 | tTyCon0 s cs = Closed $ TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) [] | 179 | tTyCon0 s cs = TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) [] |
180 | 180 | ||
181 | pattern a :~> b = Pi Visible a b | 181 | pattern 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 | ||
199 | pattern TT <- ConN _ _ | 199 | pattern TT <- ConN _ _ |
200 | where TT = Closed (tCon FTT 0 Unit []) | 200 | where TT = tCon FTT 0 Unit [] |
201 | 201 | ||
202 | pattern CUnit <- ConN FCUnit _ | 202 | pattern 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 | ||
222 | pattern EBool a <- (getEBool -> Just a) | 222 | pattern 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 | ||
227 | getEBool (hnf -> ConN FFalse _) = Just False | 227 | getEBool (hnf -> ConN FFalse _) = Just False |
228 | getEBool (hnf -> ConN FTrue _) = Just True | 228 | getEBool (hnf -> ConN FTrue _) = Just True |
229 | getEBool _ = Nothing | 229 | getEBool _ = Nothing |
230 | 230 | ||
231 | pattern ENat n <- (fromNatE -> Just n) | 231 | pattern 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 | ||
235 | fromNatE :: Exp -> Maybe Int | 235 | fromNatE :: Exp -> Maybe Int |
236 | fromNatE (hnf -> ConN FZero _) = Just 0 | 236 | fromNatE (hnf -> ConN FZero _) = Just 0 |
237 | fromNatE (hnf -> ConN FSucc (n:_)) = succ <$> fromNatE n | 237 | fromNatE (hnf -> ConN FSucc (n:_)) = succ <$> fromNatE n |
238 | fromNatE _ = Nothing | 238 | fromNatE _ = Nothing |
239 | 239 | ||
240 | mkOrdering x = Closed $ case x of | 240 | mkOrdering 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 | |||
385 | varType' :: Int -> [Exp] -> Exp | 385 | varType' :: Int -> [Exp] -> Exp |
386 | varType' i vs = vs !! i | 386 | varType' i vs = vs !! i |
387 | 387 | ||
388 | pattern Closed :: () => ClosedExp a => a -> a | ||
389 | pattern Closed a <- a where Closed a = closedExp a | ||
390 | |||
391 | -- TODO: remove? | ||
392 | class ClosedExp a where | ||
393 | closedExp :: a -> a | ||
394 | |||
395 | instance ClosedExp ExpType where | ||
396 | closedExp (ET a b) = ET (closedExp a) (closedExp b) | ||
397 | |||
398 | instance 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 | |||
410 | instance 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 | ||
421 | instance PShow Exp where | 390 | instance 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 | ||
564 | inferTerm :: Monad m => SIName -> SExp2 -> IM m ExpType | 564 | inferTerm :: Monad m => SIName -> SExp2 -> IM m ExpType |
565 | inferTerm sn t = fmap closedExp $ recheck sn EGlobal . replaceMetas (lamPi Hidden) =<< inferN EGlobal t | 565 | inferTerm sn t = recheck sn EGlobal . replaceMetas (lamPi Hidden) =<< inferN EGlobal t |
566 | 566 | ||
567 | inferType :: Monad m => SIName -> SExp2 -> IM m Type | 567 | inferType :: Monad m => SIName -> SExp2 -> IM m Type |
568 | inferType sn t = fmap (closedExp . expr) | 568 | inferType 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 | ||