summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-05-04 09:50:11 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-05-04 09:50:11 +0200
commitc4dc2ffc92a19e93ec4b3876364c12074681ecbf (patch)
tree0a9dd9f3403917ea7d55049833fa1f1e3ae598e0 /src
parentfdcbfc66bf98cb4c463de3cf5d8572afd4ab7dad (diff)
refactoring
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/Compiler/Core.hs127
-rw-r--r--src/LambdaCube/Compiler/CoreToIR.hs4
-rw-r--r--src/LambdaCube/Compiler/Infer.hs15
3 files changed, 75 insertions, 71 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs
index 802438c8..cad76385 100644
--- a/src/LambdaCube/Compiler/Core.hs
+++ b/src/LambdaCube/Compiler/Core.hs
@@ -35,7 +35,7 @@ instance Monoid MaxDB where
35 MaxDB a `mappend` MaxDB a' = MaxDB $ max a a' 35 MaxDB a `mappend` MaxDB a' = MaxDB $ max a a'
36 where 36 where
37 max 0 x = x 37 max 0 x = x
38 max _ _ = 1 -- 38 max _ _ = 1 -- TODO
39 39
40--instance Show MaxDB where show _ = "MaxDB" 40--instance Show MaxDB where show _ = "MaxDB"
41 41
@@ -197,7 +197,7 @@ data Freq = CompileTime | RunTime -- TODO
197 deriving (Eq) 197 deriving (Eq)
198 198
199data Exp 199data Exp
200 = ELit Lit 200 = ELit Lit
201 | TType_ Freq 201 | TType_ Freq
202 | Lam_ !MaxDB Exp 202 | Lam_ !MaxDB Exp
203 | Con_ !MaxDB ConName !Int{-number of ereased arguments applied-} [Exp] 203 | Con_ !MaxDB ConName !Int{-number of ereased arguments applied-} [Exp]
@@ -217,6 +217,7 @@ data Neutral
217-------------------------------------------------------------------------------- auxiliary functions and patterns 217-------------------------------------------------------------------------------- auxiliary functions and patterns
218 218
219type Type = Exp 219type Type = Exp
220
220data ExpType = ET {expr :: Exp, ty :: Type} 221data ExpType = ET {expr :: Exp, ty :: Type}
221 deriving (Eq) 222 deriving (Eq)
222 223
@@ -232,33 +233,46 @@ pattern TType = TType_ CompileTime
232infixl 2 `App`, `app_` 233infixl 2 `App`, `app_`
233infixr 1 :~> 234infixr 1 :~>
234 235
235pattern NoLE <- (isNoRHS -> True) 236pattern NoRHS <- (isRHS -> False)
236 237
237isNoRHS RHS{} = False 238isRHS RHS{} = True
238isNoRHS _ = True 239isRHS _ = False
239 240
240-- TODO: elim 241-- TODO: elim
241pattern Reverse xs <- (reverse -> xs) 242pattern Reverse xs <- (reverse -> xs)
242 where Reverse = reverse 243 where Reverse = reverse
243 244
244pattern Fun' f vs xs n <- Fun_ _ f vs xs n 245pattern Fun' f vs xs n <- Fun_ _ f vs xs n
245 where Fun' f vs xs n = Fun_ (foldMap maxDB_ vs <> foldMap maxDB_ xs {- <> iterateN i lowerDB (maxDB_ n)-}) f vs xs n 246 where Fun' f vs xs n = Fun_ (foldMap maxDB_ vs <> foldMap maxDB_ xs {- <> maxDB_ n-}) f vs xs n
246pattern Fun f xs n = Fun' f [] xs n
247pattern UFunN a b <- (hnf -> Neut (Fun (FunName a _ t) (reverse -> b) NoLE))
248pattern DFun fn xs = Fun fn (Reverse xs) Delta
249pattern TFun' a t b = DFun (FunName' a t) b
250pattern TFun a t b = Neut (TFun' a t b)
251
252pattern CaseFun_ a b c <- CaseFun__ _ a b c 247pattern CaseFun_ a b c <- CaseFun__ _ a b c
253 where CaseFun_ a b c = CaseFun__ (maxDB_ c <> foldMap maxDB_ b) a b c 248 where CaseFun_ a b c = CaseFun__ (maxDB_ c <> foldMap maxDB_ b) a b c
254pattern TyCaseFun_ a b c <- TyCaseFun__ _ a b c 249pattern TyCaseFun_ a b c <- TyCaseFun__ _ a b c
255 where TyCaseFun_ a b c = TyCaseFun__ (foldMap maxDB_ b <> maxDB_ c) a b c 250 where TyCaseFun_ a b c = TyCaseFun__ (foldMap maxDB_ b <> maxDB_ c) a b c
256pattern App_ a b <- App__ _ a b 251pattern App_ a b <- App__ _ a b
257 where App_ a b = App__ (maxDB_ a <> maxDB_ b) a b 252 where App_ a b = App__ (maxDB_ a <> maxDB_ b) a b
258pattern CaseFun a b c = Neut (CaseFun_ a b c) 253pattern Con x n y <- Con_ _ x n y
254 where Con x n y = Con_ (foldMap maxDB_ y) x n y
255pattern TyCon x y <- TyCon_ _ x y
256 where TyCon x y = TyCon_ (foldMap maxDB_ y) x y
257pattern Lam y <- Lam_ _ y
258 where Lam y = Lam_ (lowerDB (maxDB_ y)) y
259pattern Pi v x y <- Pi_ _ v x y
260 where Pi v x y = Pi_ (maxDB_ x <> lowerDB (maxDB_ y)) v x y
261
262pattern CaseFun a b c = Neut (CaseFun_ a b c)
259pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c) 263pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c)
260pattern App a b <- Neut (App_ (Neut -> a) b) 264pattern Var a = Neut (Var_ a)
261pattern Var a = Neut (Var_ a) 265pattern App a b <- Neut (App_ (Neut -> a) b)
266pattern TFun a t b = Neut (TFun' a t b)
267
268-- global function application
269pattern Fun f xs n = Fun' f [] xs n
270
271-- unreducable function application
272pattern UFunN a b <- Neut (Fun (FunName a _ t) (reverse -> b) NoRHS)
273
274-- reducable delta function application
275pattern DFun fn xs = Fun fn (Reverse xs) Delta
262 276
263conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars 277conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars
264mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) xs 278mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) xs
@@ -266,21 +280,16 @@ mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _
266mkConPars n x@Neut{} = error $ "mkConPars!: " ++ ppShow x 280mkConPars n x@Neut{} = error $ "mkConPars!: " ++ ppShow x
267mkConPars n x = error $ "mkConPars: " ++ ppShow (n, x) 281mkConPars n x = error $ "mkConPars: " ++ ppShow (n, x)
268 282
269pattern Con x n y <- Con_ _ x n y 283pattern ConN s a <- Con (ConName s _ _) _ a
270 where Con x n y = Con_ (foldMap maxDB_ y) x n y
271pattern ConN s a <- Con (ConName s _ _) _ a
272pattern ConN' s a <- Con (ConName _ s _) _ a 284pattern ConN' s a <- Con (ConName _ s _) _ a
273tCon s i t a = Con (ConName s i t) 0 a 285tCon s i t a = Con (ConName s i t) 0 a
274tCon_ k s i t a = Con (ConName s i t) k a 286tCon_ k s i t a = Con (ConName s i t) k a
275pattern TyCon x y <- TyCon_ _ x y
276 where TyCon x y = TyCon_ (foldMap maxDB_ y) x y
277pattern Lam y <- Lam_ _ y
278 where Lam y = Lam_ (lowerDB (maxDB_ y)) y
279pattern Pi v x y <- Pi_ _ v x y
280 where Pi v x y = Pi_ (maxDB_ x <> lowerDB (maxDB_ y)) v x y
281pattern TyConN s a <- TyCon (TyConName s _ _ _ _) a 287pattern TyConN s a <- TyCon (TyConName s _ _ _ _) a
282pattern TTyCon s t a <- TyCon (TyConName s _ t _ _) a 288pattern TTyCon s t a <- TyCon (TyConName s _ t _ _) a
283pattern TTyCon0 s <- (hnf -> TyCon (TyConName s _ TType _ _) []) 289pattern TFun' a t b = DFun (FunName' a t) b
290
291
292pattern TTyCon0 s <- TyCon (TyConName s _ TType _ _) []
284 293
285tTyCon 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 294tTyCon 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
286tTyCon0 s cs = Closed $ TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) [] 295tTyCon0 s cs = Closed $ TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) []
@@ -296,19 +305,28 @@ pattern TChar <- TTyCon0 FChar where TChar = tTyCon0 FChar $ er
296pattern TOrdering <- TTyCon0 FOrdering where TOrdering = tTyCon0 FOrdering $ error "cs 8" 305pattern TOrdering <- TTyCon0 FOrdering where TOrdering = tTyCon0 FOrdering $ error "cs 8"
297pattern TVec a b <- TyConN FVecS [b, a] 306pattern TVec a b <- TyConN FVecS [b, a]
298 307
308litType = \case
309 LInt _ -> TInt
310 LFloat _ -> TFloat
311 LString _ -> TString
312 LChar _ -> TChar
313
299pattern Empty s <- TyCon (TyConName FEmpty _ _ _ _) [HString{-hnf?-} s] where 314pattern Empty s <- TyCon (TyConName FEmpty _ _ _ _) [HString{-hnf?-} s] where
300 Empty s = TyCon (TyConName FEmpty (error "todo: inum2_") (TString :~> TType) (error "todo: tcn cons 3_") $ error "Empty") [HString s] 315 Empty s = TyCon (TyConName FEmpty (error "todo: inum2_") (TString :~> TType) (error "todo: tcn cons 3_") $ error "Empty") [HString s]
301 316
302pattern TT <- ConN' _ _ where TT = Closed (tCon FTT 0 Unit []) 317pattern TT <- ConN' _ _
303pattern Zero <- ConN FZero _ where Zero = Closed (tCon FZero 0 TNat []) 318 where TT = Closed (tCon FTT 0 Unit [])
304pattern Succ n <- ConN FSucc (n:_) where Succ n = tCon FSucc 1 (TNat :~> TNat) [n] 319pattern Zero <- ConN FZero _
320 where Zero = Closed (tCon FZero 0 TNat [])
321pattern Succ n <- ConN FSucc (n:_)
322 where Succ n = tCon FSucc 1 (TNat :~> TNat) [n]
305 323
306pattern CstrT t a b = Neut (CstrT' t a b) 324pattern CstrT t a b = Neut (CstrT' t a b)
307pattern CstrT' t a b = TFun' FEqCT (TType :~> Var 0 :~> Var 1 :~> TType) [t, a, b] 325pattern CstrT' t a b = TFun' FEqCT (TType :~> Var 0 :~> Var 1 :~> TType) [t, a, b]
308pattern Coe a b w x = TFun Fcoe (TType :~> TType :~> CstrT TType (Var 1) (Var 0) :~> Var 2 :~> Var 2) [a,b,w,x] 326pattern Coe a b w x = TFun Fcoe (TType :~> TType :~> CstrT TType (Var 1) (Var 0) :~> Var 2 :~> Var 2) [a,b,w,x]
309pattern ParEval t a b = TFun FparEval (TType :~> Var 0 :~> Var 1 :~> Var 2) [t, a, b] 327pattern ParEval t a b = TFun FparEval (TType :~> Var 0 :~> Var 1 :~> Var 2) [t, a, b]
310pattern T2 a b = TFun FT2 (TType :~> TType :~> TType) [a, b] 328pattern T2 a b = TFun FT2 (TType :~> TType :~> TType) [a, b]
311pattern CSplit a b c <- UFunN FSplit [a, b, c] 329pattern CSplit a b c <- UFunN FSplit [a, b, c]
312 330
313pattern HLit a <- (hnf -> ELit a) 331pattern HLit a <- (hnf -> ELit a)
314 where HLit = ELit 332 where HLit = ELit
@@ -363,14 +381,8 @@ pmLabel' md f vs xs (hnf -> y) = Neut $ Fun_ md f vs xs y
363pmLabel :: FunName -> [Exp] -> [Exp] -> Exp -> Exp 381pmLabel :: FunName -> [Exp] -> [Exp] -> Exp -> Exp
364pmLabel f vs xs e = pmLabel' (foldMap maxDB_ vs <> foldMap maxDB_ xs) f vs xs e 382pmLabel f vs xs e = pmLabel' (foldMap maxDB_ vs <> foldMap maxDB_ xs) f vs xs e
365 383
366dropLams (hnf -> Lam x) = dropLams x 384pattern Reduced' y <- Fun' f _ xs (RHS y)
367dropLams (hnf -> Neut x) = x 385pattern Reduced y <- Neut (Reduced' y)
368
369numLams (hnf -> Lam x) = 1 + numLams x
370numLams x = 0
371
372pattern FL' y <- Fun' f _ xs (RHS y)
373pattern FL y <- Neut (FL' y)
374 386
375pattern Func n def ty xs <- (mkFunc -> Just (n, def, ty, xs)) 387pattern Func n def ty xs <- (mkFunc -> Just (n, def, ty, xs))
376 388
@@ -389,7 +401,7 @@ unFunc _ = Nothing
389unFunc_ (Neut (Fun' _ _ xs y)) = Just y 401unFunc_ (Neut (Fun' _ _ xs y)) = Just y
390unFunc_ _ = Nothing 402unFunc_ _ = Nothing
391 403
392hnf (FL y) = hnf y 404hnf (Reduced y) = hnf y
393hnf a = a 405hnf a = a
394 406
395-------------------------------------------------------------------------------- low-level toolbox 407-------------------------------------------------------------------------------- low-level toolbox
@@ -416,8 +428,8 @@ down t x | usedVar t x = Nothing
416 | otherwise = Just $ subst_ t mempty (error "impossible: down" :: Exp) x 428 | otherwise = Just $ subst_ t mempty (error "impossible: down" :: Exp) x
417 429
418instance Eq Exp where 430instance Eq Exp where
419 FL a == a' = a == a' 431 Reduced a == a' = a == a'
420 a == FL a' = a == a' 432 a == Reduced a' = a == a'
421 Lam a == Lam a' = a == a' 433 Lam a == Lam a' = a == a'
422 Pi a b c == Pi a' b' c' = (a, b, c) == (a', b', c') 434 Pi a b c == Pi a' b' c' = (a, b, c) == (a', b', c')
423 Con a n b == Con a' n' b' = (a, n, b) == (a', n', b') 435 Con a n b == Con a' n' b' = (a, n, b) == (a', n', b')
@@ -430,8 +442,8 @@ instance Eq Exp where
430 442
431instance Eq Neutral where 443instance Eq Neutral where
432 Fun' f vs a _ == Fun' f' vs' a' _ = (f, vs, a) == (f', vs', a') 444 Fun' f vs a _ == Fun' f' vs' a' _ = (f, vs, a) == (f', vs', a')
433 FL' a == a' = a == Neut a' 445 Reduced' a == a' = a == Neut a'
434 a == FL' a' = Neut a == a' 446 a == Reduced' a' = Neut a == a'
435 CaseFun_ a b c == CaseFun_ a' b' c' = (a, b, c) == (a', b', c') 447 CaseFun_ a b c == CaseFun_ a' b' c' = (a, b, c) == (a', b', c')
436 TyCaseFun_ a b c == TyCaseFun_ a' b' c' = (a, b, c) == (a', b', c') 448 TyCaseFun_ a b c == TyCaseFun_ a' b' c' = (a, b, c) == (a', b', c')
437 App_ a b == App_ a' b' = (a, b) == (a', b') 449 App_ a b == App_ a' b' = (a, b) == (a', b')
@@ -611,7 +623,7 @@ instance MkDoc Neutral where
611 g = mkDoc pr 623 g = mkDoc pr
612 f = \case 624 f = \case
613 CstrT' t a b -> shCstr (g (ET a t)) (g (ET b t)) 625 CstrT' t a b -> shCstr (g (ET a t)) (g (ET b t))
614 FL' a | pr -> g a 626 Reduced' a | pr -> g a
615 Fun' s vs (mkExpTypes (nType s) . reverse -> xs) _ -> foldl (shApp Visible) (pShow s) (g <$> xs) 627 Fun' s vs (mkExpTypes (nType s) . reverse -> xs) _ -> foldl (shApp Visible) (pShow s) (g <$> xs)
616 Var_ k -> shVar k 628 Var_ k -> shVar k
617 App_ a b -> shApp Visible (g a) (g b) 629 App_ a b -> shApp Visible (g a) (g b)
@@ -637,18 +649,18 @@ evalCaseFun a ps (Con n@(ConName _ i _) _ vs)
637 where 649 where
638 xs !!! i | i >= length xs = error $ "!!! " ++ ppShow a ++ " " ++ show i ++ " " ++ ppShow n ++ "\n" ++ ppShow ps 650 xs !!! i | i >= length xs = error $ "!!! " ++ ppShow a ++ " " ++ show i ++ " " ++ ppShow n ++ "\n" ++ ppShow ps
639 xs !!! i = xs !! i 651 xs !!! i = xs !! i
640evalCaseFun a b (FL c) = evalCaseFun a b c 652evalCaseFun a b (Reduced c) = evalCaseFun a b c
641evalCaseFun a b (Neut c) = CaseFun a b c 653evalCaseFun a b (Neut c) = CaseFun a b c
642evalCaseFun a b x = error $ "evalCaseFun: " ++ ppShow (a, x) 654evalCaseFun a b x = error $ "evalCaseFun: " ++ ppShow (a, x)
643 655
644evalTyCaseFun a b (FL c) = evalTyCaseFun a b c 656evalTyCaseFun a b (Reduced c) = evalTyCaseFun a b c
645evalTyCaseFun a b (Neut c) = TyCaseFun a b c 657evalTyCaseFun a b (Neut c) = TyCaseFun a b c
646evalTyCaseFun (TyCaseFunName FType ty) (_: t: f: _) TType = t 658evalTyCaseFun (TyCaseFunName FType ty) (_: t: f: _) TType = t
647evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) (TyCon (TyConName n' _ _ _ _) vs) | n == n' = foldl app_ t vs 659evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) (TyCon (TyConName n' _ _ _ _) vs) | n == n' = foldl app_ t vs
648--evalTyCaseFun (TyCaseFunName n ty) [_, t, f] (DFun (FunName n' _) vs) | n == n' = foldl app_ t vs -- hack 660--evalTyCaseFun (TyCaseFunName n ty) [_, t, f] (DFun (FunName n' _) vs) | n == n' = foldl app_ t vs -- hack
649evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) _ = f 661evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) _ = f
650 662
651evalCoe a b (FL x) d = evalCoe a b x d 663evalCoe a b (Reduced x) d = evalCoe a b x d
652evalCoe a b TT d = d 664evalCoe a b TT d = d
653evalCoe a b t d = Coe a b t d 665evalCoe a b t d = Coe a b t d
654 666
@@ -720,7 +732,7 @@ getFunDef s f = case s of
720 "PrimAnd" -> \case (EBool x: EBool y: _) -> EBool (x && y); xs -> f xs 732 "PrimAnd" -> \case (EBool x: EBool y: _) -> EBool (x && y); xs -> f xs
721 "PrimOr" -> \case (EBool x: EBool y: _) -> EBool (x || y); xs -> f xs 733 "PrimOr" -> \case (EBool x: EBool y: _) -> EBool (x || y); xs -> f xs
722 "PrimXor" -> \case (EBool x: EBool y: _) -> EBool (x /= y); xs -> f xs 734 "PrimXor" -> \case (EBool x: EBool y: _) -> EBool (x /= y); xs -> f xs
723 "PrimNot" -> \case (TNat: _: _: EBool x: _) -> EBool $ not x; xs -> f xs 735 "PrimNot" -> \case ((hnf -> TNat): _: _: EBool x: _) -> EBool $ not x; xs -> f xs
724 736
725 _ -> f 737 _ -> f
726 738
@@ -739,11 +751,11 @@ cstr = f []
739 f_ (_: ns) typ{-down?-} (down 0 -> Just a) (down 0 -> Just a') = f ns typ a a' 751 f_ (_: ns) typ{-down?-} (down 0 -> Just a) (down 0 -> Just a') = f ns typ a a'
740 f_ ns TType (Pi h a b) (Pi h' a' b') | h == h' = t2 (f ns TType a a') (f ((a, a'): ns) TType b b') 752 f_ ns TType (Pi h a b) (Pi h' a' b') | h == h' = t2 (f ns TType a a') (f ((a, a'): ns) TType b b')
741 753
742 f_ [] TType (UFunN FVecScalar [a, b]) (UFunN FVecScalar [a', b']) = t2 (f [] TNat a a') (f [] TType b b') 754 f_ [] TType (hnf -> UFunN FVecScalar [a, b]) (hnf -> UFunN FVecScalar [a', b']) = t2 (f [] TNat a a') (f [] TType b b')
743 f_ [] TType (UFunN FVecScalar [a, b]) (TVec a' b') = t2 (f [] TNat a a') (f [] TType b b') 755 f_ [] TType (hnf -> UFunN FVecScalar [a, b]) (TVec a' b') = t2 (f [] TNat a a') (f [] TType b b')
744 f_ [] TType (UFunN FVecScalar [a, b]) t@NonNeut = t2 (f [] TNat a (ENat 1)) (f [] TType b t) 756 f_ [] TType (hnf -> UFunN FVecScalar [a, b]) t@NonNeut = t2 (f [] TNat a (ENat 1)) (f [] TType b t)
745 f_ [] TType (TVec a' b') (UFunN FVecScalar [a, b]) = t2 (f [] TNat a' a) (f [] TType b' b) 757 f_ [] TType (TVec a' b') (hnf -> UFunN FVecScalar [a, b]) = t2 (f [] TNat a' a) (f [] TType b' b)
746 f_ [] TType t@NonNeut (UFunN FVecScalar [a, b]) = t2 (f [] TNat a (ENat 1)) (f [] TType b t) 758 f_ [] TType t@NonNeut (hnf -> UFunN FVecScalar [a, b]) = t2 (f [] TNat a (ENat 1)) (f [] TType b t)
747 759
748 f_ [] typ a@Neut{} a' = CstrT typ a a' 760 f_ [] typ a@Neut{} a' = CstrT typ a a'
749 f_ [] typ a a'@Neut{} = CstrT typ a a' 761 f_ [] typ a a'@Neut{} = CstrT typ a a'
@@ -755,7 +767,7 @@ cstr = f []
755 767
756pattern NonNeut <- (nonNeut -> True) 768pattern NonNeut <- (nonNeut -> True)
757 769
758nonNeut FL{} = True 770nonNeut Reduced{} = True
759nonNeut Neut{} = False 771nonNeut Neut{} = False
760nonNeut _ = True 772nonNeut _ = True
761 773
@@ -790,7 +802,7 @@ twoOpBool f t (HFloat x) (HFloat y) = Just $ EBool $ f x y
790twoOpBool f t (HInt x) (HInt y) = Just $ EBool $ f x y 802twoOpBool f t (HInt x) (HInt y) = Just $ EBool $ f x y
791twoOpBool f t (HString x) (HString y) = Just $ EBool $ f x y 803twoOpBool f t (HString x) (HString y) = Just $ EBool $ f x y
792twoOpBool f t (HChar x) (HChar y) = Just $ EBool $ f x y 804twoOpBool f t (HChar x) (HChar y) = Just $ EBool $ f x y
793twoOpBool f TNat (ENat x) (ENat y) = Just $ EBool $ f x y 805twoOpBool f (hnf -> TNat) (ENat x) (ENat y) = Just $ EBool $ f x y
794twoOpBool _ _ _ _ = Nothing 806twoOpBool _ _ _ _ = Nothing
795 807
796app_ :: Exp -> Exp -> Exp 808app_ :: Exp -> Exp -> Exp
@@ -799,11 +811,10 @@ app_ (Con s n xs) a = if n < conParams s then Con s (n+1) xs else Con s n (xs ++
799app_ (TyCon s xs) a = TyCon s (xs ++ [a]) 811app_ (TyCon s xs) a = TyCon s (xs ++ [a])
800app_ (Neut f) a = neutApp f a 812app_ (Neut f) a = neutApp f a
801 where 813 where
802 neutApp (FL' x) a = app_ x a -- ??? 814 neutApp (Reduced' x) a = app_ x a -- ???
803 neutApp (Fun' f vs xs (Lam e)) a = pmLabel f vs (a: xs) (subst 0 a e) 815 neutApp (Fun' f vs xs (Lam e)) a = pmLabel f vs (a: xs) (subst 0 a e)
804 neutApp f a = Neut $ App_ f a 816 neutApp f a = Neut $ App_ f a
805 817
806
807class NType a where nType :: a -> Type 818class NType a where nType :: a -> Type
808 819
809instance NType FunName where nType (FunName _ _ t) = t 820instance NType FunName where nType (FunName _ _ t) = t
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs
index 8b590447..b344ecd9 100644
--- a/src/LambdaCube/Compiler/CoreToIR.hs
+++ b/src/LambdaCube/Compiler/CoreToIR.hs
@@ -891,11 +891,11 @@ chain' vs t _ = error $ "chain: " ++ ppShow t
891 891
892mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs 892mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs
893 893
894unLab' (FL x) = unLab' x 894unLab' (Reduced x) = unLab' x
895unLab' (RHS x) = unLab' x -- TODO: remove 895unLab' (RHS x) = unLab' x -- TODO: remove
896unLab' x = x 896unLab' x = x
897 897
898unFunc' (FL x) = unFunc' x -- todo: remove? 898unFunc' (Reduced x) = unFunc' x -- todo: remove?
899unFunc' (UFL x) = unFunc' x 899unFunc' (UFL x) = unFunc' x
900unFunc' (RHS x) = unFunc' x -- TODO: remove 900unFunc' (RHS x) = unFunc' x -- TODO: remove
901unFunc' x = x 901unFunc' x = x
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index 18062471..f727ea4b 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -19,7 +19,7 @@ module LambdaCube.Compiler.Infer
19 ( SName, Lit(..), Visibility(..) 19 ( SName, Lit(..), Visibility(..)
20 , Exp (..), Neutral (..), ExpType(..), GlobalEnv 20 , Exp (..), Neutral (..), ExpType(..), GlobalEnv
21 , pattern Var, pattern CaseFun, pattern TyCaseFun, pattern App_, app_, pattern TType 21 , pattern Var, pattern CaseFun, pattern TyCaseFun, pattern App_, app_, pattern TType
22 , pattern Con, pattern TyCon, pattern Pi, pattern Lam, pattern Fun, pattern Func, pattern FL, pattern UFL, unFunc_ 22 , pattern Con, pattern TyCon, pattern Pi, pattern Lam, pattern Fun, pattern Func, pattern Reduced, pattern UFL, unFunc_
23 , outputType, boolType, trueExp 23 , outputType, boolType, trueExp
24 , down, Subst (..), free, subst, upDB 24 , down, Subst (..), free, subst, upDB
25 , initEnv, Env(..) 25 , initEnv, Env(..)
@@ -198,13 +198,6 @@ parent = \case
198 198
199-------------------------------------------------------------------------------- simple typing 199-------------------------------------------------------------------------------- simple typing
200 200
201litType = \case
202 LInt _ -> TInt
203 LFloat _ -> TFloat
204 LString _ -> TString
205 LChar _ -> TChar
206
207
208neutType te = \case 201neutType te = \case
209 App_ f x -> appTy (neutType te f) x 202 App_ f x -> appTy (neutType te f) x
210 Var_ i -> snd $ varType "C" i te 203 Var_ i -> snd $ varType "C" i te
@@ -393,7 +386,7 @@ inferN_ tellTrace = infer where
393 ELet1 le te b{-in-} -> infer (ELet2 le (replaceMetas' eet{-let-}) te) b{-in-} 386 ELet1 le te b{-in-} -> infer (ELet2 le (replaceMetas' eet{-let-}) te) b{-in-}
394 EBind2_ si BMeta tt_ te 387 EBind2_ si BMeta tt_ te
395 | ERHS te' <- te -> refocus (ERHS $ EBind2_ si BMeta tt_ te') eet 388 | ERHS te' <- te -> refocus (ERHS $ EBind2_ si BMeta tt_ te') eet
396 | Unit <- tt -> refocus te $ subst 0 TT eet 389 | (hnf -> Unit) <- tt -> refocus te $ subst 0 TT eet
397 | Empty msg <- tt -> throwError' $ ETypeError (text msg) si 390 | Empty msg <- tt -> throwError' $ ETypeError (text msg) si
398 | T2 x y <- tt, let te' = EBind2_ si BMeta (up 1 y) $ EBind2_ si BMeta x te 391 | T2 x y <- tt, let te' = EBind2_ si BMeta (up 1 y) $ EBind2_ si BMeta x te
399 -> refocus te' $ subst 2 (t2C (Var 1) (Var 0)) $ up 2 eet 392 -> refocus te' $ subst 2 (t2C (Var 1) (Var 0)) $ up 2 eet
@@ -578,7 +571,7 @@ dependentVars ie = cycle mempty
578 grow = flip foldMap ie $ \case 571 grow = flip foldMap ie $ \case
579 (n, t) -> (Set.singleton n <-> freeVars t) <> case t of 572 (n, t) -> (Set.singleton n <-> freeVars t) <> case t of
580 CstrT _{-todo-} ty f -> freeVars ty <-> freeVars f 573 CstrT _{-todo-} ty f -> freeVars ty <-> freeVars f
581 CSplit a b c -> freeVars a <-> (freeVars b <> freeVars c) 574 (hnf -> CSplit a b c) -> freeVars a <-> (freeVars b <> freeVars c)
582 _ -> mempty 575 _ -> mempty
583 where 576 where
584 a --> b = \s -> if Set.null $ a `Set.intersection` s then mempty else b 577 a --> b = \s -> if Set.null $ a `Set.intersection` s then mempty else b
@@ -740,7 +733,7 @@ mkELet n x xt = {-(if null vs then id else trace_ $ "mkELet " ++ show (length vs
740 getFix x _ = x 733 getFix x _ = x
741 734
742 735
743removeHiddenUnit (Pi Hidden Unit (down 0 -> Just t)) = removeHiddenUnit t 736removeHiddenUnit (Pi Hidden (hnf -> Unit) (down 0 -> Just t)) = removeHiddenUnit t
744removeHiddenUnit (Pi h a b) = Pi h a $ removeHiddenUnit b 737removeHiddenUnit (Pi h a b) = Pi h a $ removeHiddenUnit b
745removeHiddenUnit t = t 738removeHiddenUnit t = t
746 739