@@ -874,21 +874,21 @@ expandParams dec ps ns infs tm = en tm
874874 mkShadow (MN i n) = MN (i+1) n
875875 mkShadow (NS x s) = NS (mkShadow x) s
876876
877− en (PLam n t s)
877+ en (PLam fc n t s)
878878 | n `elem` (map fst ps ++ ns)
879879 = let n' = mkShadow n in
880− PLam n' (en t) (en (shadow n n' s))
881− | otherwise = PLam n (en t) (en s)
880+ PLam fc n' (en t) (en (shadow n n' s))
881+ | otherwise = PLam fc n (en t) (en s)
882882 en (PPi p n t s)
883883 | n `elem` (map fst ps ++ ns)
884884 = let n' = mkShadow n in -- TODO THINK SHADOWING TacImp?
885885 PPi (enTacImp p) n' (en t) (en (shadow n n' s))
886886 | otherwise = PPi (enTacImp p) n (en t) (en s)
887− en (PLet n ty v s)
887+ en (PLet fc n ty v s)
888888 | n `elem` (map fst ps ++ ns)
889889 = let n' = mkShadow n in
890− PLet n' (en ty) (en v) (en (shadow n n' s))
891− | otherwise = PLet n (en ty) (en v) (en s)
890+ PLet fc n' (en ty) (en v) (en (shadow n n' s))
891+ | otherwise = PLet fc n (en ty) (en v) (en s)
892892 -- FIXME: Should only do this in a type signature!
893893 en (PDPair f p (PRef f' n) t r)
894894 | n `elem` (map fst ps ++ ns) && t /= Placeholder
@@ -1396,7 +1396,7 @@ implicitise syn ignore ist tm = -- trace ("INCOMING " ++ showImp True tm) $
13961396 = do (decls, ns) <- get
13971397 let isn = concatMap (namesIn uvars ist) as
13981398 put (decls, nub (ns ++ (isn `dropAll` (env ++ map fst (getImps decls)))))
1399− imps top env (PLam n ty sc)
1399+ imps top env (PLam fc n ty sc)
14001400 = do imps False env ty
14011401 imps False (n:env) sc
14021402 imps top env (PHidden tm) = imps False env tm
@@ -1488,15 +1488,24 @@ addImpl' inpat env infns ist ptm
14881488 -- definition which is passed through addImpl again with more scope
14891489 -- information
14901490 PCase fc c' os
1491− ai qq env ds (PLam n ty sc)
1492− = let ty' = ai qq env ds ty
1493− sc' = ai qq ((n, Just ty):env) ds sc in
1494− PLam n ty' sc'
1495− ai qq env ds (PLet n ty val sc)
1496− = let ty' = ai qq env ds ty
1497− val' = ai qq env ds val
1498− sc' = ai qq ((n, Just ty):env) ds sc in
1499− PLet n ty' val' sc'
1491+ -- If the name in a lambda is a constructor name, do this as a 'case'
1492+ -- instead (it is harmless to do so, especially since the lambda will
1493+ -- be lifted anyway!)
1494+ ai qq env ds (PLam fc n ty sc)
1495+ = case lookupDef n (tt_ctxt ist) of
1496+ [] -> let ty' = ai qq env ds ty
1497+ sc' = ai qq ((n, Just ty):env) ds sc in
1498+ PLam fc n ty' sc'
1499+ _ -> ai qq env ds (PLam fc (sMN 0 "lamp") ty
1500+ (PCase fc (PRef fc (sMN 0 "lamp") )
1501+ [(PRef fc n, sc)]))
1502+ ai qq env ds (PLet fc n ty val sc)
1503+ = case lookupDef n (tt_ctxt ist) of
1504+ [] -> let ty' = ai qq env ds ty
1505+ val' = ai qq env ds val
1506+ sc' = ai qq ((n, Just ty):env) ds sc in
1507+ PLet fc n ty' val' sc'
1508+ _ -> ai qq env ds (PCase fc val [(PRef fc n, sc)])
15001509 ai qq env ds (PPi p n ty sc)
15011510 = let ty' = ai qq env ds ty
15021511 sc' = ai qq ((n, Just ty):env) ds sc in
@@ -1696,7 +1705,7 @@ stripUnmatchable i (PApp fc fn args) = PApp fc fn (fmap (fmap su) args) where
16961705 else PAlternative b alts'
16971706 su (PPair fc p l r) = PPair fc p (su l) (su r)
16981707 su (PDPair fc p l t r) = PDPair fc p (su l) (su t) (su r)
1699− su t@(PLam _ _ _) = PHidden t
1708+ su t@(PLam fc _ _ _) = PHidden t
17001709 su t@(PPi _ _ _ _) = PHidden t
17011710 su t@(PEq _ _ _ _ _) = PHidden t
17021711 su t = t
@@ -1843,13 +1852,13 @@ matchClause' names i x y = checkRpts $ match (fullApp x) (fullApp y) where
18431852 match (PPi _ _ t s) (PPi _ _ t' s') = do mt <- match' t t'
18441853 ms <- match' s s'
18451854 return (mt ++ ms)
1846− match (PLam _ t s) (PLam _ t' s') = do mt <- match' t t'
1847− ms <- match' s s'
1848− return (mt ++ ms)
1849− match (PLet _ t ty s) (PLet _ t' ty' s') = do mt <- match' t t'
1850− mty <- match' ty ty'
1851− ms <- match' s s'
1852− return (mt ++ mty ++ ms)
1855+ match (PLam _ _ t s) (PLam _ _ t' s') = do mt <- match' t t'
1856+ ms <- match' s s'
1857+ return (mt ++ ms)
1858+ match (PLet _ _ t ty s) (PLet _ _ t' ty' s') = do mt <- match' t t'
1859+ mty <- match' ty ty'
1860+ ms <- match' s s'
1861+ return (mt ++ mty ++ ms)
18531862 match (PHidden x) (PHidden y)
18541863 | RightOK xs <- match x y = return xs -- to collect variables
18551864 | otherwise = return [] -- Otherwise hidden things are unmatchable
@@ -1892,7 +1901,7 @@ substMatch n = substMatchShadow n []
18921901substMatchShadow :: Name -> [Name] -> PTerm -> PTerm -> PTerm
18931902substMatchShadow n shs tm t = sm shs t where
18941903 sm xs (PRef _ n') | n == n' = tm
1895− sm xs (PLam x t sc) = PLam x (sm xs t) (sm xs sc)
1904+ sm xs (PLam fc x t sc) = PLam fc x (sm xs t) (sm xs sc)
18961905 sm xs (PPi p x t sc)
18971906 | x `elem` xs
18981907 = let x' = nextName x in
@@ -1919,9 +1928,9 @@ substMatchShadow n shs tm t = sm shs t where
19191928shadow :: Name -> Name -> PTerm -> PTerm
19201929shadow n n' t = sm t where
19211930 sm (PRef fc x) | n == x = PRef fc n'
1922− sm (PLam x t sc) | n /= x = PLam x (sm t) (sm sc)
1931+ sm (PLam fc x t sc) | n /= x = PLam fc x (sm t) (sm sc)
19231932 sm (PPi p x t sc) | n /=x = PPi p x (sm t) (sm sc)
1924− sm (PLet x t v sc) | n /= x = PLet x (sm t) (sm v) (sm sc)
1933+ sm (PLet fc x t v sc) | n /= x = PLet fc x (sm t) (sm v) (sm sc)
19251934 sm (PApp f x as) = PApp f (sm x) (map (fmap sm) as)
19261935 sm (PAppBind f x as) = PAppBind f (sm x) (map (fmap sm) as)
19271936 sm (PCase f x as) = PCase f (sm x) (map (pmap sm) as)
@@ -1960,7 +1969,7 @@ mkUniqueNames env tm = evalState (mkUniq tm) (S.fromList env) where
19601969 mkUniqT tac = return tac
19611970
19621971 mkUniq :: PTerm -> State (S.Set Name) PTerm
1963− mkUniq (PLam n ty sc)
1972+ mkUniq (PLam fc n ty sc)
19641973 = do env <- get
19651974 (n', sc') <-
19661975 if n `S.member` env
@@ -1971,7 +1980,7 @@ mkUniqueNames env tm = evalState (mkUniq tm) (S.fromList env) where
19711980 put (S.insert n' env)
19721981 ty' <- mkUniq ty
19731982 sc'' <- mkUniq sc'
1974− return $! PLam n' ty' sc''
1983+ return $! PLam fc n' ty' sc''
19751984 mkUniq (PPi p n ty sc)
19761985 = do env <- get
19771986 (n', sc') <-
@@ -1984,7 +1993,7 @@ mkUniqueNames env tm = evalState (mkUniq tm) (S.fromList env) where
19841993 ty' <- mkUniq ty
19851994 sc'' <- mkUniq sc'
19861995 return $! PPi p n' ty' sc''
1987− mkUniq (PLet n ty val sc)
1996+ mkUniq (PLet fc n ty val sc)
19881997 = do env <- get
19891998 (n', sc') <-
19901999 if n `S.member` env
@@ -1995,7 +2004,7 @@ mkUniqueNames env tm = evalState (mkUniq tm) (S.fromList env) where
19952004 put (S.insert n' env)
19962005 ty' <- mkUniq ty; val' <- mkUniq val
19972006 sc'' <- mkUniq sc'
1998− return $! PLet n' ty' val' sc''
2007+ return $! PLet fc n' ty' val' sc''
19992008 mkUniq (PApp fc t args)
20002009 = do t' <- mkUniq t
20012010 args' <- mapM mkUniqA args