diff options
Diffstat (limited to 'src/LambdaCube')
-rw-r--r-- | src/LambdaCube/Compiler.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 98 |
3 files changed, 41 insertions, 61 deletions
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs index 0af04c56..62f7a49e 100644 --- a/src/LambdaCube/Compiler.hs +++ b/src/LambdaCube/Compiler.hs | |||
@@ -49,7 +49,7 @@ import LambdaCube.Compiler.Pretty hiding ((</>)) | |||
49 | import LambdaCube.Compiler.Parser (Module(..), Export(..), ImportItems (..), runDefParser, parseLC) | 49 | import LambdaCube.Compiler.Parser (Module(..), Export(..), ImportItems (..), runDefParser, parseLC) |
50 | import LambdaCube.Compiler.Lexer as Exported (Range(..)) | 50 | import LambdaCube.Compiler.Lexer as Exported (Range(..)) |
51 | import LambdaCube.Compiler.Infer (PolyEnv(..), showError, joinPolyEnvs, filterPolyEnv, inference_, extractDesugarInfo) | 51 | import LambdaCube.Compiler.Infer (PolyEnv(..), showError, joinPolyEnvs, filterPolyEnv, inference_, extractDesugarInfo) |
52 | import LambdaCube.Compiler.Infer as Exported (Infos, listAllInfos, listTypeInfos, listTraceInfos, Exp, outputType, boolType, trueExp) | 52 | import LambdaCube.Compiler.Infer as Exported (Infos, listAllInfos, listTypeInfos, listTraceInfos, Exp, outputType, boolType, trueExp, unfixlabel) |
53 | import LambdaCube.Compiler.CoreToIR | 53 | import LambdaCube.Compiler.CoreToIR |
54 | 54 | ||
55 | -- inlcude path for: Builtins, Internals and Prelude | 55 | -- inlcude path for: Builtins, Internals and Prelude |
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 7bbd4a8b..9e741a01 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -847,7 +847,7 @@ chain' vs t _ = error $ "chain: " ++ show t | |||
847 | 847 | ||
848 | mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs | 848 | mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs |
849 | 849 | ||
850 | unLab' (FixLabel_ f _ _ x) = {-trace_ ("fix " ++ show f) $ -} unLab' x | 850 | unLab' (FL _ _ x) = unLab' x |
851 | unLab' x = x | 851 | unLab' x = x |
852 | 852 | ||
853 | instance Subst Exp ExpTV where | 853 | instance Subst Exp ExpTV where |
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index e19265ec..7b97b5d7 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -17,8 +17,8 @@ | |||
17 | module LambdaCube.Compiler.Infer | 17 | module LambdaCube.Compiler.Infer |
18 | ( Binder (..), SName, Lit(..), Visibility(..) | 18 | ( Binder (..), SName, Lit(..), Visibility(..) |
19 | , Exp (..), Neutral (..), ExpType, GlobalEnv | 19 | , Exp (..), Neutral (..), ExpType, GlobalEnv |
20 | , pattern Var, pattern CaseFun, pattern TyCaseFun, pattern App_, pattern LabelEnd | 20 | , pattern Var, pattern CaseFun, pattern TyCaseFun, pattern App_, pattern LabelEnd, pattern FL |
21 | , pattern Con, pattern TyCon, pattern Pi, pattern Lam, pattern Fun | 21 | , pattern Con, pattern TyCon, pattern Pi, pattern Lam, pattern Fun, pattern ELit |
22 | , outputType, boolType, trueExp | 22 | , outputType, boolType, trueExp |
23 | , down, Subst (..), free | 23 | , down, Subst (..), free |
24 | , litType | 24 | , litType |
@@ -54,16 +54,15 @@ import LambdaCube.Compiler.Parser | |||
54 | 54 | ||
55 | data Exp | 55 | data Exp |
56 | = TType | 56 | = TType |
57 | | ELit Lit | 57 | | ELit_ Lit |
58 | | Con_ MaxDB ConName !Int{-number of ereased arguments applied-} [Exp] | 58 | | Con_ MaxDB ConName !Int{-number of ereased arguments applied-} [Exp] |
59 | | TyCon_ MaxDB TyConName [Exp] | 59 | | TyCon_ MaxDB TyConName [Exp] |
60 | | Pi_ MaxDB Visibility Exp Exp | 60 | | Pi_ MaxDB Visibility Exp Exp |
61 | | Lam_ MaxDB Exp | 61 | | Lam_ MaxDB Exp |
62 | | Neut Neutral | 62 | | Neut Neutral |
63 | | FixLabel_ Type{-type-} [Exp]{-args-} Exp{-def-} Exp{-fix def args-} | ||
64 | deriving (Show) | 63 | deriving (Show) |
65 | 64 | ||
66 | pattern FixLabel f xs e <- FixLabel_ f xs e _ where FixLabel f xs e = {-trace_ ("fixl: " ++ ppShow e ++ " " ++ ppShow xs) $ -} let x = FixLabel_ f [] e (subst 0 x e) in foldl app_ x xs | 65 | pattern ELit a <- (unfixlabel -> ELit_ a) where ELit = ELit_ |
67 | 66 | ||
68 | data Neutral | 67 | data Neutral |
69 | = Fun_ MaxDB FunName !Int{-number of missing parameters-} [Exp]{-given parameters-} Neutral{-unfolded expression-}{-not neut?-} | 68 | = Fun_ MaxDB FunName !Int{-number of missing parameters-} [Exp]{-given parameters-} Neutral{-unfolded expression-}{-not neut?-} |
@@ -110,7 +109,7 @@ pattern NoLE <- (isNoLabelEnd -> True) | |||
110 | isNoLabelEnd (LabelEnd_ _) = False | 109 | isNoLabelEnd (LabelEnd_ _) = False |
111 | isNoLabelEnd _ = True | 110 | isNoLabelEnd _ = True |
112 | 111 | ||
113 | pattern Fun f i xs n <- Fun_ _ f i xs n where Fun f i xs n = Fun_ (foldMap maxDB_ xs <> iterateN i lowerDB (maxDB_ n)) f i xs n | 112 | pattern Fun f i xs n <- Fun_ _ f i xs n where Fun f i xs n = Fun_ (foldMap maxDB_ xs {- <> iterateN i lowerDB (maxDB_ n)-}) f i xs n |
114 | pattern UFunN a b <- Neut (Fun (FunName a _) _ b NoLE) | 113 | pattern UFunN a b <- Neut (Fun (FunName a _) _ b NoLE) |
115 | pattern UTFun a t b <- Neut (Fun (FunName a t) _ b NoLE) | 114 | pattern UTFun a t b <- Neut (Fun (FunName a t) _ b NoLE) |
116 | pattern DFun_ fn xs <- Fun fn 0 xs (Delta _) where | 115 | pattern DFun_ fn xs <- Fun fn 0 xs (Delta _) where |
@@ -131,16 +130,17 @@ pattern App a b <- Neut (App_ (Neut -> a) b) | |||
131 | pattern Var a = Neut (Var_ a) | 130 | pattern Var a = Neut (Var_ a) |
132 | 131 | ||
133 | conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars | 132 | conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars |
134 | mkConPars n (snd . getParams -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) xs | 133 | mkConPars n (snd . getParams . unfixlabel -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) xs |
135 | --mkConPars 0 TType = [] -- ? | 134 | --mkConPars 0 TType = [] -- ? |
136 | mkConPars n x@Neut{} = error $ "mkConPars!: " ++ ppShow x | 135 | mkConPars n x@Neut{} = error $ "mkConPars!: " ++ ppShow x |
137 | mkConPars n x = error $ "mkConPars: " ++ ppShow (n, x) | 136 | mkConPars n x = error $ "mkConPars: " ++ ppShow (n, x) |
138 | 137 | ||
139 | makeCaseFunPars te n = case neutType te n of | 138 | makeCaseFunPars te n = case neutType te n of |
140 | TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs -> take pars xs | 139 | (unfixlabel -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) -> take pars xs |
140 | x -> error $ "makeCaseFunPars: " ++ ppShow x | ||
141 | 141 | ||
142 | makeCaseFunPars' te n = case neutType' te n of | 142 | makeCaseFunPars' te n = case neutType' te n of |
143 | TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs -> take pars xs | 143 | (unfixlabel -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) -> take pars xs |
144 | 144 | ||
145 | pattern Closed :: () => Up a => a -> a | 145 | pattern Closed :: () => Up a => a -> a |
146 | pattern Closed a <- a where Closed a = closedExp a | 146 | pattern Closed a <- a where Closed a = closedExp a |
@@ -220,20 +220,20 @@ toNatE 0 = Zero | |||
220 | toNatE n | n > 0 = Closed (Succ (toNatE (n - 1))) | 220 | toNatE n | n > 0 = Closed (Succ (toNatE (n - 1))) |
221 | 221 | ||
222 | fromNatE :: Exp -> Maybe Int | 222 | fromNatE :: Exp -> Maybe Int |
223 | fromNatE (ConN' 0 _) = Just 0 | 223 | fromNatE (unfixlabel -> ConN' 0 _) = Just 0 |
224 | fromNatE (ConN' 1 [n]) = (1 +) <$> fromNatE n | 224 | fromNatE (unfixlabel -> ConN' 1 [n]) = (1 +) <$> fromNatE n |
225 | fromNatE _ = Nothing | 225 | fromNatE _ = Nothing |
226 | 226 | ||
227 | fromNatE' :: Exp -> Maybe Int | 227 | fromNatE' :: Exp -> Maybe Int |
228 | fromNatE' Zero = Just 0 | 228 | fromNatE' (unfixlabel -> Zero) = Just 0 |
229 | fromNatE' (Succ n) = (1 +) <$> fromNatE' n | 229 | fromNatE' (unfixlabel -> Succ n) = (1 +) <$> fromNatE' n |
230 | fromNatE' _ = Nothing | 230 | fromNatE' _ = Nothing |
231 | 231 | ||
232 | mkBool False = Closed $ tCon "False" 0 TBool [] | 232 | mkBool False = Closed $ tCon "False" 0 TBool [] |
233 | mkBool True = Closed $ tCon "True" 1 TBool [] | 233 | mkBool True = Closed $ tCon "True" 1 TBool [] |
234 | 234 | ||
235 | getEBool (ConN' 0 _) = Just False | 235 | getEBool (unfixlabel -> ConN' 0 _) = Just False |
236 | getEBool (ConN' 1 _) = Just True | 236 | getEBool (unfixlabel -> ConN' 1 _) = Just True |
237 | getEBool _ = Nothing | 237 | getEBool _ = Nothing |
238 | 238 | ||
239 | mkOrdering x = Closed $ case x of | 239 | mkOrdering x = Closed $ case x of |
@@ -257,14 +257,10 @@ pattern LabelEnd x = Neut (LabelEnd_ x) | |||
257 | 257 | ||
258 | pmLabel' :: FunName -> Int -> [Exp] -> Exp -> Exp | 258 | pmLabel' :: FunName -> Int -> [Exp] -> Exp -> Exp |
259 | pmLabel' (FunName _ _) 0 as (Neut (Delta (SData f))) = f as | 259 | pmLabel' (FunName _ _) 0 as (Neut (Delta (SData f))) = f as |
260 | pmLabel' f 0 xs (unfixlabel -> LabelEnd y) = y | 260 | --pmLabel' f 0 xs (unfixlabel -> LabelEnd y) = y |
261 | pmLabel' f i xs (unfixlabel -> Neut y) = Neut $ Fun f i xs y | 261 | pmLabel' f i xs (unfixlabel -> Neut y) = Neut $ Fun f i xs y |
262 | pmLabel' f i xs y = error $ "pmLabel: " ++ show (f, i, length xs, y) | 262 | pmLabel' f i xs y = error $ "pmLabel: " ++ show (f, i, length xs, y) |
263 | 263 | ||
264 | addFixLabel x y z = | ||
265 | FixLabel x y | ||
266 | z | ||
267 | |||
268 | pmLabel :: FunName -> Int -> [Exp] -> Exp -> Exp | 264 | pmLabel :: FunName -> Int -> [Exp] -> Exp -> Exp |
269 | pmLabel f i xs e = pmLabel' f (i + numLams e) xs (Neut $ dropLams e) | 265 | pmLabel f i xs e = pmLabel' f (i + numLams e) xs (Neut $ dropLams e) |
270 | 266 | ||
@@ -278,7 +274,6 @@ pattern FL' f xs y = Fun f 0 xs (LabelEnd_ y) | |||
278 | pattern FL f xs y = Neut (FL' f xs y) | 274 | pattern FL f xs y = Neut (FL' f xs y) |
279 | 275 | ||
280 | unfixlabel (FL _ _ y) = unfixlabel y | 276 | unfixlabel (FL _ _ y) = unfixlabel y |
281 | unfixlabel (FixLabel_ _ _ _ a) = unfixlabel a | ||
282 | unfixlabel a = a | 277 | unfixlabel a = a |
283 | 278 | ||
284 | unlabelend (LabelEnd a) = unlabelend a | 279 | unlabelend (LabelEnd a) = unlabelend a |
@@ -295,12 +290,9 @@ down t x | used t x = Nothing | |||
295 | | otherwise = Just $ subst t (error "impossible: down" :: Exp) x | 290 | | otherwise = Just $ subst t (error "impossible: down" :: Exp) x |
296 | 291 | ||
297 | instance Eq Exp where | 292 | instance Eq Exp where |
298 | FL f xs _ == FL f' xs' _ = (f, xs) == (f', xs') | 293 | FL f xs _ == FL f' xs' _ | (f, xs) == (f', xs') = True |
299 | FL _ _ a == a' = a == a' | 294 | FL _ _ a == a' = a == a' |
300 | a == FL _ _ a' = a == a' | 295 | a == FL _ _ a' = a == a' |
301 | FixLabel_ _ a f _ == FixLabel_ _ a' f' _ = (f, a) == (f', a') | ||
302 | FixLabel_ _ _ _ a == a' = a == a' | ||
303 | a == FixLabel_ _ _ _ a' = a == a' | ||
304 | LabelEnd a == a' = a == a' | 296 | LabelEnd a == a' = a == a' |
305 | a == LabelEnd a' = a == a' | 297 | a == LabelEnd a' = a == a' |
306 | Lam a == Lam a' = a == a' | 298 | Lam a == Lam a' = a == a' |
@@ -334,7 +326,6 @@ instance Up Exp where | |||
334 | Pi_ md h a b -> Pi_ (upDB n md) h (f i a) (f (i+1) b) | 326 | Pi_ md h a b -> Pi_ (upDB n md) h (f i a) (f (i+1) b) |
335 | Con_ md s pn as -> Con_ (upDB n md) s pn $ map (f i) as | 327 | Con_ md s pn as -> Con_ (upDB n md) s pn $ map (f i) as |
336 | TyCon_ md s as -> TyCon_ (upDB n md) s $ map (f i) as | 328 | TyCon_ md s as -> TyCon_ (upDB n md) s $ map (f i) as |
337 | FixLabel_ fn xs y u -> FixLabel_ (f i fn) (f i <$> xs) (f (i+1) y) (f i u) | ||
338 | Neut x -> Neut $ up_ n i x | 329 | Neut x -> Neut $ up_ n i x |
339 | 330 | ||
340 | used i e | 331 | used i e |
@@ -342,7 +333,6 @@ instance Up Exp where | |||
342 | | otherwise = ((getAny .) . fold ((Any .) . (==))) i e | 333 | | otherwise = ((getAny .) . fold ((Any .) . (==))) i e |
343 | 334 | ||
344 | fold f i = \case | 335 | fold f i = \case |
345 | FixLabel_ t x y _ -> {-fold f i t <> -} foldMap (fold f i) x -- <> fold f (i+1) y --todo | ||
346 | Lam b -> {-fold f i t <> todo: explain why this is not needed -} fold f (i+1) b | 336 | Lam b -> {-fold f i t <> todo: explain why this is not needed -} fold f (i+1) b |
347 | Pi _ a b -> fold f i a <> fold f (i+1) b | 337 | Pi _ a b -> fold f i a <> fold f (i+1) b |
348 | Con _ _ as -> foldMap (fold f i) as | 338 | Con _ _ as -> foldMap (fold f i) as |
@@ -357,7 +347,6 @@ instance Up Exp where | |||
357 | Con_ c _ _ _ -> c | 347 | Con_ c _ _ _ -> c |
358 | TyCon_ c _ _ -> c | 348 | TyCon_ c _ _ -> c |
359 | 349 | ||
360 | FixLabel_ t x y _ -> maxDB_ t <> foldMap maxDB_ x <> lowerDB (maxDB_ y) | ||
361 | TType -> mempty | 350 | TType -> mempty |
362 | ELit _ -> mempty | 351 | ELit _ -> mempty |
363 | Neut x -> maxDB_ x | 352 | Neut x -> maxDB_ x |
@@ -367,7 +356,6 @@ instance Up Exp where | |||
367 | Pi_ _ a b c -> Pi_ mempty a (closedExp b) c | 356 | Pi_ _ a b c -> Pi_ mempty a (closedExp b) c |
368 | Con_ _ a b c -> Con_ mempty a b (closedExp <$> c) | 357 | Con_ _ a b c -> Con_ mempty a b (closedExp <$> c) |
369 | TyCon_ _ a b -> TyCon_ mempty a (closedExp <$> b) | 358 | TyCon_ _ a b -> TyCon_ mempty a (closedExp <$> b) |
370 | FixLabel_ fn xs b u -> FixLabel_ (closedExp fn) (closedExp <$> xs) (closedExp b) u | ||
371 | e@TType{} -> e | 359 | e@TType{} -> e |
372 | e@ELit{} -> e | 360 | e@ELit{} -> e |
373 | Neut a -> Neut $ closedExp a | 361 | Neut a -> Neut $ closedExp a |
@@ -388,7 +376,6 @@ instance Subst Exp Exp where | |||
388 | d@Delta{} -> Neut d | 376 | d@Delta{} -> Neut d |
389 | f i e | cmpDB i e = e | 377 | f i e | cmpDB i e = e |
390 | f i e = case e of | 378 | f i e = case e of |
391 | FixLabel_ fn z v u -> FixLabel (f i fn) (f i <$> z) (f (i+1) v) --(f i u) | ||
392 | Lam b -> Lam (f (i+1) b) | 379 | Lam b -> Lam (f (i+1) b) |
393 | Con s n as -> Con s n $ f i <$> as | 380 | Con s n as -> Con s n $ f i <$> as |
394 | Pi h a b -> Pi h (f i a) (f (i+1) b) | 381 | Pi h a b -> Pi h (f i a) (f (i+1) b) |
@@ -417,7 +404,7 @@ instance Up Neutral where | |||
417 | CaseFun_ _ as n -> foldMap (fold f i) as <> fold f i n | 404 | CaseFun_ _ as n -> foldMap (fold f i) as <> fold f i n |
418 | TyCaseFun_ _ as n -> foldMap (fold f i) as <> fold f i n | 405 | TyCaseFun_ _ as n -> foldMap (fold f i) as <> fold f i n |
419 | App_ a b -> fold f i a <> fold f i b | 406 | App_ a b -> fold f i a <> fold f i b |
420 | Fun _ j x d -> foldMap (fold f i) x <> fold f (i+j) d | 407 | Fun _ j x d -> foldMap (fold f i) x -- <> fold f (i+j) d |
421 | LabelEnd_ x -> fold f i x | 408 | LabelEnd_ x -> fold f i x |
422 | Delta{} -> mempty | 409 | Delta{} -> mempty |
423 | 410 | ||
@@ -460,12 +447,10 @@ evalCaseFun a ps (Con n@(ConName _ i _) _ vs) | |||
460 | xs !!! i | i >= length xs = error $ "!!! " ++ show a ++ " " ++ show i ++ " " ++ show n ++ "\n" ++ ppShow ps | 447 | xs !!! i | i >= length xs = error $ "!!! " ++ show a ++ " " ++ show i ++ " " ++ show n ++ "\n" ++ ppShow ps |
461 | xs !!! i = xs !! i | 448 | xs !!! i = xs !! i |
462 | evalCaseFun a b (FL _ _ c) = evalCaseFun a b c | 449 | evalCaseFun a b (FL _ _ c) = evalCaseFun a b c |
463 | evalCaseFun a b (FixLabel_ _ _ _ c) = evalCaseFun a b c | ||
464 | evalCaseFun a b (Neut c) = CaseFun a b c | 450 | evalCaseFun a b (Neut c) = CaseFun a b c |
465 | evalCaseFun a b x = error $ "evalCaseFun: " ++ show (a, x) | 451 | evalCaseFun a b x = error $ "evalCaseFun: " ++ show (a, x) |
466 | 452 | ||
467 | evalTyCaseFun a b (FL _ _ c) = evalTyCaseFun a b c | 453 | evalTyCaseFun a b (FL _ _ c) = evalTyCaseFun a b c |
468 | evalTyCaseFun a b (FixLabel_ _ _ _ c) = evalTyCaseFun a b c | ||
469 | evalTyCaseFun a b (Neut c) = TyCaseFun a b c | 454 | evalTyCaseFun a b (Neut c) = TyCaseFun a b c |
470 | evalTyCaseFun (TyCaseFunName "match'Type" ty) [_, t, f] TType = t | 455 | evalTyCaseFun (TyCaseFunName "match'Type" ty) [_, t, f] TType = t |
471 | evalTyCaseFun (TyCaseFunName n ty) [_, t, f] (TyCon (TyConName n' _ _ _ _) vs) | n == n' = foldl app_ t vs | 456 | evalTyCaseFun (TyCaseFunName n ty) [_, t, f] (TyCon (TyConName n' _ _ _ _) vs) | n == n' = foldl app_ t vs |
@@ -544,8 +529,6 @@ cstr = f [] | |||
544 | f _ _ a a' | a == a' = Unit | 529 | f _ _ a a' | a == a' = Unit |
545 | f ns typ (LabelEnd a) a' = f ns typ a a' | 530 | f ns typ (LabelEnd a) a' = f ns typ a a' |
546 | f ns typ a (LabelEnd a') = f ns typ a a' | 531 | f ns typ a (LabelEnd a') = f ns typ a a' |
547 | f ns typ (FixLabel_ _ _ _ a) a' = f ns typ a a' | ||
548 | f ns typ a (FixLabel_ _ _ _ a') = f ns typ a a' | ||
549 | f ns typ (FL _ _ a) a' = f ns typ a a' | 532 | f ns typ (FL _ _ a) a' = f ns typ a a' |
550 | f ns typ a (FL _ _ a') = f ns typ a a' | 533 | f ns typ a (FL _ _ a') = f ns typ a a' |
551 | f ns typ (Con a n xs) (Con a' n' xs') | a == a' && n == n' && length xs == length xs' = | 534 | f ns typ (Con a n xs) (Con a' n' xs') | a == a' && n == n' && length xs == length xs' = |
@@ -638,10 +621,9 @@ app_ :: Exp -> Exp -> Exp | |||
638 | app_ (Lam x) a = subst 0 a x | 621 | app_ (Lam x) a = subst 0 a x |
639 | app_ (Con s n xs) a = if n < conParams s then Con s (n+1) xs else Con s n (xs ++ [a]) | 622 | app_ (Con s n xs) a = if n < conParams s then Con s (n+1) xs else Con s n (xs ++ [a]) |
640 | app_ (TyCon s xs) a = TyCon s (xs ++ [a]) | 623 | app_ (TyCon s xs) a = TyCon s (xs ++ [a]) |
641 | app_ (FixLabel_ f xs e u) a = FixLabel_ f (xs ++ [a]) e (app_ u a) | ||
642 | app_ (Neut f) a = neutApp f a | 624 | app_ (Neut f) a = neutApp f a |
643 | 625 | ||
644 | neutApp (FL' _ _ x) a = app_ x a | 626 | neutApp (FL' _ _ x) a = app_ x a -- ??? |
645 | neutApp (Fun f i xs e) a | i > 0 = pmLabel f (i-1) (xs ++ [a]) (subst (i-1) (up (i-1) a) $ Neut e) | 627 | neutApp (Fun f i xs e) a | i > 0 = pmLabel f (i-1) (xs ++ [a]) (subst (i-1) (up (i-1) a) $ Neut e) |
646 | neutApp (LabelEnd_ x) a = Neut $ LabelEnd_ (app_ x a) -- ??? | 628 | neutApp (LabelEnd_ x) a = Neut $ LabelEnd_ (app_ x a) -- ??? |
647 | neutApp d@Delta{} _ = Neut d | 629 | neutApp d@Delta{} _ = Neut d |
@@ -742,7 +724,7 @@ instance NType TyConName where nType (TyConName _ _ t _ _) = t | |||
742 | instance NType CaseFunName where nType (CaseFunName _ t _) = t | 724 | instance NType CaseFunName where nType (CaseFunName _ t _) = t |
743 | instance NType TyCaseFunName where nType (TyCaseFunName _ t) = t | 725 | instance NType TyCaseFunName where nType (TyCaseFunName _ t) = t |
744 | 726 | ||
745 | conType (snd . getParams -> TyCon (TyConName _ _ _ cs _) _) (ConName _ n t) = t --snd $ cs !! n | 727 | conType (snd . getParams . unfixlabel -> TyCon (TyConName _ _ _ cs _) _) (ConName _ n t) = t --snd $ cs !! n |
746 | 728 | ||
747 | neutType te = \case | 729 | neutType te = \case |
748 | App_ f x -> appTy (neutType te f) x | 730 | App_ f x -> appTy (neutType te f) x |
@@ -929,7 +911,7 @@ inferN_ tellTrace = infer where | |||
929 | focus2 :: Env -> CEnv ExpType -> IM m ExpType' | 911 | focus2 :: Env -> CEnv ExpType -> IM m ExpType' |
930 | focus2 env eet = case env of | 912 | focus2 env eet = case env of |
931 | ELet1 le te b{-in-} -> infer (ELet2 le (replaceMetas' eet{-let-}) te) b{-in-} | 913 | ELet1 le te b{-in-} -> infer (ELet2 le (replaceMetas' eet{-let-}) te) b{-in-} |
932 | EBind2_ si BMeta tt te | 914 | EBind2_ si BMeta tt_ te |
933 | | Unit <- tt -> refocus te $ subst 0 TT eet | 915 | | Unit <- tt -> refocus te $ subst 0 TT eet |
934 | | Empty msg <- tt -> throwError' $ ETypeError msg si | 916 | | Empty msg <- tt -> throwError' $ ETypeError msg si |
935 | | T2 x y <- tt, let te' = EBind2_ si BMeta (up 1 y) $ EBind2_ si BMeta x te | 917 | | T2 x y <- tt, let te' = EBind2_ si BMeta (up 1 y) $ EBind2_ si BMeta x te |
@@ -942,17 +924,18 @@ inferN_ tellTrace = infer where | |||
942 | -> refocus (EBind2_ si h (up 1 x) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet | 924 | -> refocus (EBind2_ si h (up 1 x) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet |
943 | | ELet2 le (x, xt) te' <- te, Just b' <- down 0 tt | 925 | | ELet2 le (x, xt) te' <- te, Just b' <- down 0 tt |
944 | -> refocus (ELet2 le (up 1 x, up 1 xt) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet | 926 | -> refocus (ELet2 le (up 1 x, up 1 xt) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet |
945 | | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt te') $ up1_ 1 x) eet | 927 | | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt_ te') $ up1_ 1 x) eet |
946 | | ELet1 le te' x <- te, floatLetMeta $ snd $ replaceMetas' $ Meta tt $ eet | 928 | | ELet1 le te' x <- te, floatLetMeta $ snd $ replaceMetas' $ Meta tt_ $ eet |
947 | -> refocus (ELet1 le (EBind2_ si BMeta tt te') $ up1_ 1 x) eet | 929 | -> refocus (ELet1 le (EBind2_ si BMeta tt_ te') $ up1_ 1 x) eet |
948 | | CheckAppType si h t te' x <- te -> refocus (CheckAppType si h (up 1 t) (EBind2_ si BMeta tt te') $ up1 x) eet | 930 | | CheckAppType si h t te' x <- te -> refocus (CheckAppType si h (up 1 t) (EBind2_ si BMeta tt_ te') $ up1 x) eet |
949 | | EApp1 si h te' x <- te -> refocus (EApp1 si h (EBind2_ si BMeta tt te') $ up1 x) eet | 931 | | EApp1 si h te' x <- te -> refocus (EApp1 si h (EBind2_ si BMeta tt_ te') $ up1 x) eet |
950 | | EApp2 si h x te' <- te -> refocus (EApp2 si h (up 1 x) $ EBind2_ si BMeta tt te') eet | 932 | | EApp2 si h x te' <- te -> refocus (EApp2 si h (up 1 x) $ EBind2_ si BMeta tt_ te') eet |
951 | | CheckType_ si t te' <- te -> refocus (CheckType_ si (up 1 t) $ EBind2_ si BMeta tt te') eet | 933 | | CheckType_ si t te' <- te -> refocus (CheckType_ si (up 1 t) $ EBind2_ si BMeta tt_ te') eet |
952 | -- | CheckIType x te' <- te -> refocus (CheckType_ si (up 1 t) $ EBind2_ si BMeta tt te') eet | 934 | -- | CheckIType x te' <- te -> refocus (CheckType_ si (up 1 t) $ EBind2_ si BMeta tt te') eet |
953 | | ELabelEnd te' <- te -> refocus (ELabelEnd $ EBind2_ si BMeta tt te') eet | 935 | | ELabelEnd te' <- te -> refocus (ELabelEnd $ EBind2_ si BMeta tt_ te') eet |
954 | | otherwise -> focus2 te $ Meta tt eet | 936 | | otherwise -> focus2 te $ Meta tt_ eet |
955 | where | 937 | where |
938 | tt = unfixlabel tt_ | ||
956 | refocus = refocus_ focus2 | 939 | refocus = refocus_ focus2 |
957 | cst :: ExpType -> Exp -> Maybe (IM m ExpType') | 940 | cst :: ExpType -> Exp -> Maybe (IM m ExpType') |
958 | cst x = \case | 941 | cst x = \case |
@@ -1050,7 +1033,6 @@ recheck' msg' e (x, xt) = (recheck_ "main" (checkEnv e) (x, xt), xt) | |||
1050 | (TyCon s as, zt) -> checkApps (show s) [] zt (TyCon s) te (nType s) as | 1033 | (TyCon s as, zt) -> checkApps (show s) [] zt (TyCon s) te (nType s) as |
1051 | (CaseFun s@(CaseFunName _ t pars) as n, zt) -> checkApps (show s) [] zt (\xs -> evalCaseFun s (init $ drop pars xs) (last xs)) te (nType s) (makeCaseFunPars te n ++ as ++ [Neut n]) | 1034 | (CaseFun s@(CaseFunName _ t pars) as n, zt) -> checkApps (show s) [] zt (\xs -> evalCaseFun s (init $ drop pars xs) (last xs)) te (nType s) (makeCaseFunPars te n ++ as ++ [Neut n]) |
1052 | (TyCaseFun s [m, t, f] n, zt) -> checkApps (show s) [] zt (\[m, t, n, f] -> evalTyCaseFun s [m, t, f] n) te (nType s) [m, t, Neut n, f] | 1035 | (TyCaseFun s [m, t, f] n, zt) -> checkApps (show s) [] zt (\[m, t, n, f] -> evalTyCaseFun s [m, t, f] n) te (nType s) [m, t, Neut n, f] |
1053 | (FixLabel_ f xs x u, zt) -> checkApps "fixlab" [] zt (\xs -> FixLabel_ f xs x u) te f xs -- TODO: recheck x | ||
1054 | (Neut (Fun f i a x), zt) -> checkApps "lab" [] zt (\xs -> Neut $ Fun f i xs x) te (nType f) a -- TODO: recheck x | 1036 | (Neut (Fun f i a x), zt) -> checkApps "lab" [] zt (\xs -> Neut $ Fun f i xs x) te (nType f) a -- TODO: recheck x |
1055 | (LabelEnd x, zt) -> LabelEnd $ recheck_ msg te (x, zt) | 1037 | (LabelEnd x, zt) -> LabelEnd $ recheck_ msg te (x, zt) |
1056 | (Neut d@Delta{}, zt) -> Neut d | 1038 | (Neut d@Delta{}, zt) -> Neut d |
@@ -1059,7 +1041,7 @@ recheck' msg' e (x, xt) = (recheck_ "main" (checkEnv e) (x, xt), xt) | |||
1059 | | t == zt = f $ reverse acc | 1041 | | t == zt = f $ reverse acc |
1060 | | otherwise = | 1042 | | otherwise = |
1061 | error_ $ "checkApps' " ++ s ++ " " ++ msg ++ "\n" ++ showEnvExp te{-todo-} (t, TType) ++ "\n\n" ++ showEnvExp te (zt, TType) | 1043 | error_ $ "checkApps' " ++ s ++ " " ++ msg ++ "\n" ++ showEnvExp te{-todo-} (t, TType) ++ "\n\n" ++ showEnvExp te (zt, TType) |
1062 | checkApps s acc zt f te t@(Pi h x y) (b_: xs) = checkApps (s++"+") (b: acc) zt f te (appTy t b) xs where b = recheck_ "checkApps" te (b_, x) | 1044 | checkApps s acc zt f te t@(unfixlabel -> Pi h x y) (b_: xs) = checkApps (s++"+") (b: acc) zt f te (appTy t b) xs where b = recheck_ "checkApps" te (b_, x) |
1063 | checkApps s acc zt f te t _ = | 1045 | checkApps s acc zt f te t _ = |
1064 | error_ $ "checkApps " ++ s ++ " " ++ msg ++ "\n" ++ showEnvExp te{-todo-} (t, TType) ++ "\n\n" ++ showEnvExp e (x, xt) | 1046 | error_ $ "checkApps " ++ s ++ " " ++ msg ++ "\n" ++ showEnvExp te{-todo-} (t, TType) ++ "\n\n" ++ showEnvExp e (x, xt) |
1065 | 1047 | ||
@@ -1263,15 +1245,15 @@ handleStmt defs = \case | |||
1263 | withEnv e = local $ second (<> e) | 1245 | withEnv e = local $ second (<> e) |
1264 | 1246 | ||
1265 | mkELet (False, n) x xt = x | 1247 | mkELet (False, n) x xt = x |
1266 | mkELet (True, n) x t{-type of x-} | 1248 | mkELet (True, n) x xt = term |
1267 | | Just (t, f, i) <- getFix x 0 = fix $ \term -> pmLabel fn i [] $ Lam f `app_` addFixLabel (nType fn) (downTo 0 i) term | ||
1268 | | otherwise = pmLabel fn 0 [] x | ||
1269 | where | 1249 | where |
1270 | fn = FunName (snd n) t | 1250 | fn = FunName (snd n) xt |
1251 | |||
1252 | term = pmLabel fn 0 [] $ getFix x 0 | ||
1271 | 1253 | ||
1272 | getFix (Lam z) i = getFix z (i+1) | 1254 | getFix (Lam z) i = Lam $ getFix z (i+1) |
1273 | getFix (FunN "primFix" [t, Lam f]) i = Just (t, f, i) | 1255 | getFix (FunN "primFix" [t, Lam f]) i = subst 0 (foldl app_ term (downTo 0 i)) f |
1274 | getFix _ _ = Nothing | 1256 | getFix x _ = x |
1275 | 1257 | ||
1276 | 1258 | ||
1277 | removeHiddenUnit (Pi Hidden Unit (down 0 -> Just t)) = removeHiddenUnit t | 1259 | removeHiddenUnit (Pi Hidden Unit (down 0 -> Just t)) = removeHiddenUnit t |
@@ -1372,7 +1354,6 @@ showEnvSExpType e c t = showDoc $ envDoc e $ epar <$> (shAnn "::" False <$> sExp | |||
1372 | expToSExp :: Exp -> SExp | 1354 | expToSExp :: Exp -> SExp |
1373 | expToSExp = \case | 1355 | expToSExp = \case |
1374 | Fun x _ -> expToSExp x | 1356 | Fun x _ -> expToSExp x |
1375 | FixLabel _ x -> expToSExp x | ||
1376 | -- Var k -> shAtom <$> shVar k | 1357 | -- Var k -> shAtom <$> shVar k |
1377 | App a b -> SApp Visible{-todo-} (expToSExp a) (expToSExp b) | 1358 | App a b -> SApp Visible{-todo-} (expToSExp a) (expToSExp b) |
1378 | {- | 1359 | {- |
@@ -1428,7 +1409,6 @@ instance MkDoc Exp where | |||
1428 | mkDoc ts e = fmap inGreen <$> f e | 1409 | mkDoc ts e = fmap inGreen <$> f e |
1429 | where | 1410 | where |
1430 | f = \case | 1411 | f = \case |
1431 | FixLabel_ _ _ _ x -> f x | ||
1432 | -- Lam h a b -> join $ shLam (used 0 b) (BLam h) <$> f a <*> pure (f b) | 1412 | -- Lam h a b -> join $ shLam (used 0 b) (BLam h) <$> f a <*> pure (f b) |
1433 | Lam b -> join $ shLam True (BLam Visible) <$> f TType{-todo!-} <*> pure (f b) | 1413 | Lam b -> join $ shLam True (BLam Visible) <$> f TType{-todo!-} <*> pure (f b) |
1434 | Pi h a b -> join $ shLam (used 0 b) (BPi h) <$> f a <*> pure (f b) | 1414 | Pi h a b -> join $ shLam (used 0 b) (BPi h) <$> f a <*> pure (f b) |