@@ -152,7 +152,7 @@ getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
152 Nothing -> []
152 Nothing -> []
153 Just ty -> checkArgs [] [] ty
153 Just ty -> checkArgs [] [] ty
154 where checkArgs :: [Name] -> [[Name]] -> Type -> [Bool]
154 where checkArgs :: [Name] -> [[Name]] -> Type -> [Bool]
155− checkArgs env ns (Bind n (Pi t _) sc)
155+ checkArgs env ns (Bind n (Pi _ t _) sc)
156 = let env' = case t of
156 = let env' = case t of
157 TType _ -> n : env
157 TType _ -> n : env
158 _ -> env in
158 _ -> env in
@@ -244,7 +244,8 @@ elab ist info emode opts fn tm
244 then solveAuto ist fn False a
244 then solveAuto ist fn False a
245 else return ()) as
245 else return ()) as
247+ itm <- if not pattern then insertImpLam t else return t
247− ct <- insertCoerce ina t
248+ ct <- insertCoerce ina itm
248 t' <- insertLazy ct
249 t' <- insertLazy ct
249 g <- goal
250 g <- goal
250 tm <- get_term
251 tm <- get_term
@@ -434,13 +435,20 @@ elab ist info emode opts fn tm
434 bindable (UN xs) = True
435 bindable (UN xs) = True
435 bindable n = implicitable n
436 bindable n = implicitable n
436 elab' ina _ f@(PInferRef fc n) = elab' ina (Just fc) (PApp fc f [])
437 elab' ina _ f@(PInferRef fc n) = elab' ina (Just fc) (PApp fc f [])
437− elab' ina _ tm@(PRef fc n)
438+ elab' ina fc' tm@(PRef fc n)
438 | pattern && not reflection && not (e_qq ina) && not (e_intype ina)
439 | pattern && not reflection && not (e_qq ina) && not (e_intype ina)
439 && isTConName n (tt_ctxt ist)
440 && isTConName n (tt_ctxt ist)
440 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
441 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
441 | pattern && not reflection && e_nomatching ina
442 | pattern && not reflection && e_nomatching ina
442 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
443 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
445+ do fty <- get_type (Var n) -- check for implicits
448+ let a' = insertScopedImps fc (normalise ctxt env fty) []
443− | otherwise = erun fc $ do apply (Var n) []; solve
450+ then erun fc $ do apply (Var n) []; solve
451+ else elab' ina fc' (PApp fc tm [])
444 elab' ina _ (PLam fc n Placeholder sc)
452 elab' ina _ (PLam fc n Placeholder sc)
445 = do -- if n is a type constructor name, this makes no sense...
453 = do -- if n is a type constructor name, this makes no sense...
446 ctxt <- get_context
454 ctxt <- get_context
@@ -468,17 +476,17 @@ elab ist info emode opts fn tm
468 elabE (ec { e_inarg = True, e_intype = True }) (Just fc) ty
476 elabE (ec { e_inarg = True, e_intype = True }) (Just fc) ty
469 elabE (ec { e_inarg = True }) (Just fc) sc
477 elabE (ec { e_inarg = True }) (Just fc) sc
471− elab' ina fc (PPi _ n Placeholder sc)
479+ elab' ina fc (PPi p n Placeholder sc)
472− = do attack; arg n (sMN 0 "ty")
480+ = do attack; arg n (is_scoped p) (sMN 0 "ty")
473 elabE (ina { e_inarg = True, e_intype = True }) fc sc
481 elabE (ina { e_inarg = True, e_intype = True }) fc sc
475− elab' ina fc (PPi _ n ty sc)
483+ elab' ina fc (PPi p n ty sc)
476 = do attack; tyn <- getNameFrom (sMN 0 "ty")
484 = do attack; tyn <- getNameFrom (sMN 0 "ty")
477 claim tyn RType
485 claim tyn RType
478 n' <- case n of
486 n' <- case n of
479 MN _ _ -> unique_hole n
487 MN _ _ -> unique_hole n
480 _ -> return n
488 _ -> return n
481− forall n' (Var tyn)
489+ forall n' (is_scoped p) (Var tyn)
482 focus tyn
490 focus tyn
483 let ec' = ina { e_inarg = True, e_intype = True }
491 let ec' = ina { e_inarg = True, e_intype = True }
484 elabE ec' fc ty
492 elabE ec' fc ty
@@ -564,7 +572,7 @@ elab ist info emode opts fn tm
564 ans <- claimArgTys env xs
572 ans <- claimArgTys env xs
565 return ((aval, (True, (Var an))) : ans)
573 return ((aval, (True, (Var an))) : ans)
566 fnTy [] ret = forget ret
574 fnTy [] ret = forget ret
567− fnTy ((x, (_, xt)) : xs) ret = RBind x (Pi xt RType) (fnTy xs ret)
575+ fnTy ((x, (_, xt)) : xs) ret = RBind x (Pi Nothing xt RType) (fnTy xs ret)
569 localVar env (PRef _ x)
577 localVar env (PRef _ x)
570 = case lookup x env of
578 = case lookup x env of
@@ -594,23 +602,25 @@ elab ist info emode opts fn tm
594-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty && not qq
602-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty && not qq
595-- = lift $ tfail (Msg "Typecase is not allowed")
603-- = lift $ tfail (Msg "Typecase is not allowed")
596 -- if f is local, just do a simple_app
604 -- if f is local, just do a simple_app
597− elab' ina _ tm@(PApp fc (PRef _ f) args)
605+ elab' ina _ tm@(PApp fc (PRef _ f) args_in)
598 | pattern && not reflection && e_nomatching ina
606 | pattern && not reflection && e_nomatching ina
599 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
607 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
600 | otherwise
608 | otherwise
601 = do env <- get_env
609 = do env <- get_env
602 ty <- goal
610 ty <- goal
611+ fty <- get_type (Var f)
603 ctxt <- get_context
612 ctxt <- get_context
613+ let args = insertScopedImps fc (normalise ctxt env fty) args_in
604 let unmatchableArgs = if pattern
614 let unmatchableArgs = if pattern
605 then getUnmatchable (tt_ctxt ist) f
615 then getUnmatchable (tt_ctxt ist) f
607 -- Dot it if we're in a pattern and it isn't a constructor
617 -- Dot it if we're in a pattern and it isn't a constructor
608-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
618-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
610 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
620 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
611 && isTConName f (tt_ctxt ist)) $
621 && isTConName f (tt_ctxt ist)) $
612 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
622 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
613− if (f `elem` map fst env && length args == 1)
623+ if (f `elem` map fst env && length args == 1 && length args_in == 1)
614 then -- simple app, as below
624 then -- simple app, as below
615 do simple_app (elabE ina (Just fc) (PRef fc f))
625 do simple_app (elabE ina (Just fc) (PRef fc f))
616 (elabE (ina { e_inarg = True }) (Just fc) (getTm (head args)))
626 (elabE (ina { e_inarg = True }) (Just fc) (getTm (head args)))
@@ -1049,6 +1059,27 @@ elab ist info emode opts fn tm
1049 notImplicitable (PCase _ _ _) = True
1059 notImplicitable (PCase _ _ _) = True
1050 notImplicitable _ = False
1060 notImplicitable _ = False
1062+ insertScopedImps fc (Bind n (Pi im@(Just i) _ _) sc) xs
1064+ = pimp n (PResolveTC fc) True : insertScopedImps fc sc xs
1066+ = pimp n Placeholder True : insertScopedImps fc sc xs
1067+ insertScopedImps fc (Bind n (Pi _ _ _) sc) (x : xs)
1068+ = x : insertScopedImps fc sc xs
1069+ insertScopedImps _ _ xs = xs
1074+ let ty' = normalise (tt_ctxt ist) env ty
1077+ -- just one level at a time
1078+ addLam (Bind n (Pi (Just _) _ _) sc) t
1079+ = do impn <- unique_hole (sMN 0 "imp")
1080+ return (PLam emptyFC impn Placeholder t)
1081+ addLam _ t = return t
1052 insertCoerce ina t@(PCase _ _ _) = return t
1083 insertCoerce ina t@(PCase _ _ _) = return t
1053 insertCoerce ina t | notImplicitable t = return t
1084 insertCoerce ina t | notImplicitable t = return t
1054 insertCoerce ina t =
1085 insertCoerce ina t =
@@ -1516,9 +1547,9 @@ runTac autoSolve ist perhapsFC fn tac
1516 where tacticTy = Var (reflm "Tactic")
1547 where tacticTy = Var (reflm "Tactic")
1517 listTy = Var (sNS (sUN "List") ["List", "Prelude"])
1548 listTy = Var (sNS (sUN "List") ["List", "Prelude"])
1518 scriptTy = (RBind (sMN 0 "__pi_arg")
1549 scriptTy = (RBind (sMN 0 "__pi_arg")
1519− (Pi (RApp listTy envTupleType) RType)
1550+ (Pi Nothing (RApp listTy envTupleType) RType)
1520 (RBind (sMN 1 "__pi_arg")
1551 (RBind (sMN 1 "__pi_arg")
1521− (Pi (Var $ reflm "TT") RType) tacticTy))
1552+ (Pi Nothing (Var $ reflm "TT") RType) tacticTy))
1522 runT (ByReflection tm) -- run the reflection function 'tm' on the
1553 runT (ByReflection tm) -- run the reflection function 'tm' on the
1523 -- goal, then apply the resulting reflected Tactic
1554 -- goal, then apply the resulting reflected Tactic
1524 = do tgoal <- goal
1555 = do tgoal <- goal
@@ -1791,7 +1822,7 @@ reifyTTBinderApp :: (Term -> ElabD a) -> Name -> [Term] -> ElabD (Binder a)
1791reifyTTBinderApp reif f [t]
1822reifyTTBinderApp reif f [t]
1792 | f == reflm "Lam" = liftM Lam (reif t)
1823 | f == reflm "Lam" = liftM Lam (reif t)
1793reifyTTBinderApp reif f [t, k]
1824reifyTTBinderApp reif f [t, k]
1794− | f == reflm "Pi" = liftM2 Pi (reif t) (reif k)
1825+ | f == reflm "Pi" = liftM2 (Pi Nothing) (reif t) (reif k)
1795reifyTTBinderApp reif f [x, y]
1826reifyTTBinderApp reif f [x, y]
1796 | f == reflm "Let" = liftM2 Let (reif x) (reif y)
1827 | f == reflm "Let" = liftM2 Let (reif x) (reif y)
1797reifyTTBinderApp reif f [x, y]
1828reifyTTBinderApp reif f [x, y]
@@ -1934,7 +1965,7 @@ reflectQuotePattern unq (Bind n b x)
1934 fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
1965 fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
1936 focus t'; reflectQuotePattern unq t
1967 focus t'; reflectQuotePattern unq t
1937− reflectBinderQuotePattern unq (Pi t k)
1968+ reflectBinderQuotePattern unq (Pi _ t k)
1938 = do t' <- claimTT (sMN 0 "ty") ; movelast t'
1969 = do t' <- claimTT (sMN 0 "ty") ; movelast t'
1939 k' <- claimTT (sMN 0 "k"); movelast k';
1970 k' <- claimTT (sMN 0 "k"); movelast k';
1940 fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
1971 fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
@@ -2084,7 +2115,7 @@ reflectBinder = reflectBinderQuote []
2084reflectBinderQuote :: [Name] -> Binder Term -> Raw
2115reflectBinderQuote :: [Name] -> Binder Term -> Raw
2085reflectBinderQuote unq (Lam t)
2116reflectBinderQuote unq (Lam t)
2086 = reflCall "Lam" [Var (reflm "TT"), reflectQuote unq t]
2117 = reflCall "Lam" [Var (reflm "TT"), reflectQuote unq t]
2087−reflectBinderQuote unq (Pi t k)
2118+reflectBinderQuote unq (Pi _ t k)
2088 = reflCall "Pi" [Var (reflm "TT"), reflectQuote unq t, reflectQuote unq k]
2119 = reflCall "Pi" [Var (reflm "TT"), reflectQuote unq t, reflectQuote unq k]
2089reflectBinderQuote unq (Let x y)
2120reflectBinderQuote unq (Let x y)
2090 = reflCall "Let" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2121 = reflCall "Let" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]