@@ -31,43 +31,52 @@ checkDef ns = do ctxt <- getContext
31 mapM (\(n, t) -> do (t', _) <- tclift $ recheck ctxt [] t
31 mapM (\(n, t) -> do (t', _) <- tclift $ recheck ctxt [] t
32 return (n, t')) ns
32 return (n, t')) ns
34−elabType :: ElabInfo -> FC -> Name -> PTerm -> Idris ()
34+elabType :: ElabInfo -> SyntaxInfo -> FC -> Name -> PTerm -> Idris ()
35−elabType info fc n_in ty_in = let ty = piBind (params info) ty_in
35+elabType info syn fc n ty' = {- let ty' = piBind (params info) ty_in
36− n = liftname info n_in in
36+ n = liftname info n_in in -}
37 do checkUndefined fc n
37 do checkUndefined fc n
38 ctxt <- getContext
38 ctxt <- getContext
40+ ty' <- implicit syn n ty'
41+ let ty = addImpl i ty'
39− logLvl 2 $ "Type " ++ showImp True ty
42+ logLvl 2 $ show n ++ " type " ++ showImp True ty
40 ((ty', defer), log) <- tclift $ elaborate ctxt n (Set 0)
43 ((ty', defer), log) <- tclift $ elaborate ctxt n (Set 0)
41− (erun fc (build info False ty))
44+ (erun fc (build i info False ty))
42 (cty, _) <- tclift $ recheck ctxt [] ty'
45 (cty, _) <- tclift $ recheck ctxt [] ty'
43 logLvl 2 $ "---> " ++ show cty
46 logLvl 2 $ "---> " ++ show cty
44 let nty = normalise ctxt [] cty
47 let nty = normalise ctxt [] cty
45 ds <- checkDef ((n, nty):defer)
48 ds <- checkDef ((n, nty):defer)
46 addDeferred ds
49 addDeferred ds
48−elabData :: ElabInfo -> FC -> PData -> Idris ()
51+elabData :: ElabInfo -> SyntaxInfo -> FC -> PData -> Idris ()
49−elabData info fc (PDatadecl n t dcons)
52+elabData info syn fc (PDatadecl n t_in dcons)
50 = do iLOG (show fc)
53 = do iLOG (show fc)
51 checkUndefined fc n
54 checkUndefined fc n
52 ctxt <- getContext
55 ctxt <- getContext
57+ t_in <- implicit syn n t_in
58+ let t = addImpl i t_in
53 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
59 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
54− (erun fc (build info False t))
60+ (erun fc (build i info False t))
55 def' <- checkDef defer
61 def' <- checkDef defer
56 addDeferred def'
62 addDeferred def'
57 (cty, _) <- tclift $ recheck ctxt [] t'
63 (cty, _) <- tclift $ recheck ctxt [] t'
58 logLvl 2 $ "---> " ++ show cty
64 logLvl 2 $ "---> " ++ show cty
59 updateContext (addTyDecl n cty) -- temporary, to check cons
65 updateContext (addTyDecl n cty) -- temporary, to check cons
60− cons <- mapM (elabCon info) dcons
66+ cons <- mapM (elabCon info syn) dcons
61 ttag <- getName
67 ttag <- getName
62 setContext (addDatatype (Data n ttag cty cons) ctxt)
68 setContext (addDatatype (Data n ttag cty cons) ctxt)
64−elabCon :: ElabInfo -> (Name, PTerm, FC) -> Idris (Name, Type)
70+elabCon :: ElabInfo -> SyntaxInfo -> (Name, PTerm, FC) -> Idris (Name, Type)
65−elabCon info (n, t, fc)
71+elabCon info syn (n, t_in, fc)
66 = do checkUndefined fc n
72 = do checkUndefined fc n
67 ctxt <- getContext
73 ctxt <- getContext
75+ t_in <- implicit syn n t_in
76+ let t = addImpl i t_in
68 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
77 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
69 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
78 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
70− (erun fc (build info False t))
79+ (erun fc (build i info False t))
71 logLvl 2 $ "Rechecking " ++ show t'
80 logLvl 2 $ "Rechecking " ++ show t'
72 def' <- checkDef defer
81 def' <- checkDef defer
73 addDeferred def'
82 addDeferred def'
@@ -96,23 +105,28 @@ elabClauses info fc n_in cs = let n = liftname info n_in in
96 depat x = x
105 depat x = x
98elabVal :: ElabInfo -> PTerm -> Idris (Term, Type)
107elabVal :: ElabInfo -> PTerm -> Idris (Term, Type)
99−elabVal info tm
108+elabVal info tm_in
100 = do ctxt <- getContext
109 = do ctxt <- getContext
111+ let tm = addImpl i tm_in
101 logLvl 10 (showImp True tm)
112 logLvl 10 (showImp True tm)
102 ((tm', defer), _) <- tclift $ elaborate ctxt (MN 0 "val") infP
113 ((tm', defer), _) <- tclift $ elaborate ctxt (MN 0 "val") infP
103− (build info True (infTerm tm))
114+ (build i info True (infTerm tm))
104 logLvl 3 ("Value: " ++ show tm')
115 logLvl 3 ("Value: " ++ show tm')
105 let vtm = getInferTerm tm'
116 let vtm = getInferTerm tm'
106 logLvl 2 (show vtm)
117 logLvl 2 (show vtm)
107 tclift $ recheck ctxt [] vtm
118 tclift $ recheck ctxt [] vtm
109elabClause :: ElabInfo -> FC -> PClause -> Idris (Term, Term)
120elabClause :: ElabInfo -> FC -> PClause -> Idris (Term, Term)
110−elabClause info fc (PClause fname lhs withs rhs whereblock)
121+elabClause info fc (PClause fname lhs_in withs rhs_in whereblock)
111 = do ctxt <- getContext
122 = do ctxt <- getContext
112 -- Build the LHS as an "Infer", and pull out its type and
123 -- Build the LHS as an "Infer", and pull out its type and
113 -- pattern bindings
124 -- pattern bindings
126+ let lhs = addImpl i lhs_in
127+ logLvl 5 ("LHS: " ++ showImp True lhs)
114 ((lhs', dlhs), _) <- tclift $ elaborate ctxt (MN 0 "patLHS") infP
128 ((lhs', dlhs), _) <- tclift $ elaborate ctxt (MN 0 "patLHS") infP
115− (erun fc (build info True (infTerm lhs)))
129+ (erun fc (build i info True (infTerm lhs)))
116 let lhs_tm = getInferTerm lhs'
130 let lhs_tm = getInferTerm lhs'
117 let lhs_ty = getInferType lhs'
131 let lhs_ty = getInferType lhs'
118 logLvl 3 (show lhs_tm)
132 logLvl 3 (show lhs_tm)
@@ -122,14 +136,22 @@ elabClause info fc (PClause fname lhs withs rhs whereblock)
122 ist <- getIState
136 ist <- getIState
123 windex <- getName
137 windex <- getName
124 let winfo = pinfo (pvars ist lhs_tm) whereblock windex
138 let winfo = pinfo (pvars ist lhs_tm) whereblock windex
139+ let decls = concatMap declared whereblock
140+ let newargs = pvars ist lhs_tm
141+ let wb = map (expandParamsD decorate newargs decls) whereblock
125− mapM_ (elabDecl' winfo) whereblock
143+ mapM_ (elabDecl' info) wb
126 -- Now build the RHS, using the type of the LHS as the goal.
144 -- Now build the RHS, using the type of the LHS as the goal.
145+ i <- get -- new implicits from where block
146+ logLvl 5 (showImp True (expandParams decorate newargs decls rhs_in))
147+ let rhs = addImpl i (expandParams decorate newargs decls rhs_in)
148+ -- TODO: but don't do names in scope
127 logLvl 2 (showImp True rhs)
149 logLvl 2 (showImp True rhs)
128 ctxt <- getContext -- new context with where block added
150 ctxt <- getContext -- new context with where block added
129 ((rhs', defer), _) <-
151 ((rhs', defer), _) <-
130 tclift $ elaborate ctxt (MN 0 "patRHS") clhsty
152 tclift $ elaborate ctxt (MN 0 "patRHS") clhsty
131 (do pbinds lhs_tm
153 (do pbinds lhs_tm
132− (_, _) <- erun fc (build winfo False rhs)
154+ (_, _) <- erun fc (build i info False rhs)
133 psolve lhs_tm
155 psolve lhs_tm
134 tt <- get_term
156 tt <- get_term
135 return $ runState (collectDeferred tt) [])
157 return $ runState (collectDeferred tt) [])
@@ -141,6 +163,7 @@ elabClause info fc (PClause fname lhs withs rhs whereblock)
141 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
163 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
142 return (clhs, crhs)
164 return (clhs, crhs)
166+ decorate x = UN [show fname ++ "#" ++ show x]
144 pinfo ns ps i
167 pinfo ns ps i
145 = let ds = concatMap declared ps
168 = let ds = concatMap declared ps
146 newps = params info ++ ns
169 newps = params info ++ ns
@@ -149,32 +172,36 @@ elabClause info fc (PClause fname lhs withs rhs whereblock)
149 l = liftname info in
172 l = liftname info in
150 info { params = newps,
173 info { params = newps,
151 inblock = newb,
174 inblock = newb,
152− liftname = (\n -> case lookupCtxt n newb of
175+ liftname = id -- (\n -> case lookupCtxt n newb of
153− Nothing -> n
176+ -- Nothing -> n
154− _ -> MN i (show n)) . l
177+ -- _ -> MN i (show n)) . l
157−elabClause info fc (PWith fname lhs withs wval withblock)
180+elabClause info fc (PWith fname lhs_in withs wval_in withblock)
158 = do ctxt <- getContext
181 = do ctxt <- getContext
159 -- Build the LHS as an "Infer", and pull out its type and
182 -- Build the LHS as an "Infer", and pull out its type and
160 -- pattern bindings
183 -- pattern bindings
185+ let lhs = addImpl i lhs_in
186+ logLvl 5 ("LHS: " ++ showImp True lhs)
161 ((lhs', dlhs), _) <- tclift $ elaborate ctxt (MN 0 "patLHS") infP
187 ((lhs', dlhs), _) <- tclift $ elaborate ctxt (MN 0 "patLHS") infP
162− (erun fc (build info True (infTerm lhs)))
188+ (erun fc (build i info True (infTerm lhs)))
163 let lhs_tm = getInferTerm lhs'
189 let lhs_tm = getInferTerm lhs'
164 let lhs_ty = getInferType lhs'
190 let lhs_ty = getInferType lhs'
165 let ret_ty = getRetTy lhs_ty
191 let ret_ty = getRetTy lhs_ty
166 logLvl 3 (show lhs_tm)
192 logLvl 3 (show lhs_tm)
167 (clhs, clhsty) <- tclift $ recheck ctxt [] lhs_tm
193 (clhs, clhsty) <- tclift $ recheck ctxt [] lhs_tm
168 logLvl 5 ("Checked " ++ show clhs)
194 logLvl 5 ("Checked " ++ show clhs)
169− logLvl 5 ("Checking " ++ show wval)
170 let bargs = getPBtys lhs_tm
195 let bargs = getPBtys lhs_tm
196+ let wval = addImpl i wval_in
197+ logLvl 5 ("Checking " ++ showImp True wval)
171 -- Elaborate wval in this context
198 -- Elaborate wval in this context
172 ((wval', defer), _) <-
199 ((wval', defer), _) <-
173 tclift $ elaborate ctxt (MN 0 "withRHS")
200 tclift $ elaborate ctxt (MN 0 "withRHS")
174 (bindTyArgs PVTy bargs infP)
201 (bindTyArgs PVTy bargs infP)
175 (do pbinds lhs_tm
202 (do pbinds lhs_tm
176 -- TODO: may want where here - see winfo abpve
203 -- TODO: may want where here - see winfo abpve
177− (_', d) <- erun fc (build info False (infTerm wval))
204+ (_', d) <- erun fc (build i info False (infTerm wval))
178 psolve lhs_tm
205 psolve lhs_tm
179 tt <- get_term
206 tt <- get_term
180 return (tt, d))
207 return (tt, d))
@@ -188,6 +215,8 @@ elabClause info fc (PWith fname lhs withs wval withblock)
188 let wtype = bindTyArgs Pi (bargs ++ [(MN 0 "warg", getRetTy cwvalty)]) ret_ty
215 let wtype = bindTyArgs Pi (bargs ++ [(MN 0 "warg", getRetTy cwvalty)]) ret_ty
189 logLvl 3 ("New function type " ++ show wtype)
216 logLvl 3 ("New function type " ++ show wtype)
190 let wname = MN windex (show fname)
217 let wname = MN windex (show fname)
218+ let imps = getImps wtype -- add to implicits context
219+ put (i { idris_implicits = addDef wname imps (idris_implicits i) })
191 def' <- checkDef [(wname, wtype)]
220 def' <- checkDef [(wname, wtype)]
192 addDeferred def'
221 addDeferred def'
@@ -203,10 +232,11 @@ elabClause info fc (PWith fname lhs withs wval withblock)
203 [pexp wval])
232 [pexp wval])
204 logLvl 3 ("New RHS " ++ show rhs)
233 logLvl 3 ("New RHS " ++ show rhs)
205 ctxt <- getContext -- New context with block added
234 ctxt <- getContext -- New context with block added
206 ((rhs', defer), _) <-
236 ((rhs', defer), _) <-
207 tclift $ elaborate ctxt (MN 0 "wpatRHS") clhsty
237 tclift $ elaborate ctxt (MN 0 "wpatRHS") clhsty
208 (do pbinds lhs_tm
238 (do pbinds lhs_tm
209− (_, d) <- erun fc (build info False rhs)
239+ (_, d) <- erun fc (build i info False rhs)
210 psolve lhs_tm
240 psolve lhs_tm
211 tt <- get_term
241 tt <- get_term
212 return (tt, d))
242 return (tt, d))
@@ -215,21 +245,30 @@ elabClause info fc (PWith fname lhs withs wval withblock)
215 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
245 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
216 return (clhs, crhs)
246 return (clhs, crhs)
248+ getImps (Bind n (Pi _) t) = pexp Placeholder : getImps t
218 mkAuxC wname lhs ns (PClauses fc n cs)
251 mkAuxC wname lhs ns (PClauses fc n cs)
219 | n == fname = do cs' <- mapM (mkAux wname lhs ns) cs
252 | n == fname = do cs' <- mapM (mkAux wname lhs ns) cs
220 return $ PClauses fc wname cs'
253 return $ PClauses fc wname cs'
221 | otherwise = fail $ "with clause uses wrong function name " ++ show n
254 | otherwise = fail $ "with clause uses wrong function name " ++ show n
222 mkAuxC wname lhs ns d = return $ d
255 mkAuxC wname lhs ns d = return $ d
224− mkAux wname toplhs ns (PClause n tm (w:ws) rhs wheres)
257+ mkAux wname toplhs ns (PClause n tm_in (w:ws) rhs wheres)
259+ let tm = addImpl i tm_in
225− = do logLvl 2 ("Matching " ++ show tm ++ " against " ++ show toplhs)
260+ logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
261+ showImp True toplhs)
226 case matchClause toplhs tm of
262 case matchClause toplhs tm of
227 Nothing -> fail "with clause does not match top level"
263 Nothing -> fail "with clause does not match top level"
228 Just mvars -> do logLvl 3 ("Match vars : " ++ show mvars)
264 Just mvars -> do logLvl 3 ("Match vars : " ++ show mvars)
229 lhs <- updateLHS n wname mvars ns tm w
265 lhs <- updateLHS n wname mvars ns tm w
230 return $ PClause wname lhs ws rhs wheres
266 return $ PClause wname lhs ws rhs wheres
231− mkAux wname toplhs ns (PWith n tm (w:ws) wval wheres)
267+ mkAux wname toplhs ns (PWith n tm_in (w:ws) wval wheres)
269+ let tm = addImpl i tm_in
232− = do logLvl 2 ("Matching " ++ show tm ++ " against " ++ show toplhs)
270+ logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
271+ showImp True toplhs)
233 case matchClause toplhs tm of
272 case matchClause toplhs tm of
234 Nothing -> fail "with clause does not match top level"
273 Nothing -> fail "with clause does not match top level"
235 Just mvars -> do lhs <- updateLHS n wname mvars ns tm w
274 Just mvars -> do lhs <- updateLHS n wname mvars ns tm w
@@ -268,10 +307,10 @@ elabDecl info d = idrisCatch (elabDecl' info d) (\e -> iputStrLn (report e))
269elabDecl' info (PFix _ _ _) = return () -- nothing to elaborate
308elabDecl' info (PFix _ _ _) = return () -- nothing to elaborate
270elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
309elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
271−elabDecl' info (PTy f n ty) = do iLOG $ "Elaborating type decl " ++ show n
310+elabDecl' info (PTy s f n ty) = do iLOG $ "Elaborating type decl " ++ show n
272− elabType info f n ty
311+ elabType info s f n ty
273−elabDecl' info (PData f d) = do iLOG $ "Elaborating " ++ show (d_name d)
312+elabDecl' info (PData s f d) = do iLOG $ "Elaborating " ++ show (d_name d)
274− elabData info f d
313+ elabData info s f d
275elabDecl' info d@(PClauses f n ps) = do iLOG $ "Elaborating clause " ++ show n
314elabDecl' info d@(PClauses f n ps) = do iLOG $ "Elaborating clause " ++ show n
276 elabClauses info f n ps
315 elabClauses info f n ps
277elabDecl' info (PParams f ns ps) = mapM_ (elabDecl' pinfo) ps
316elabDecl' info (PParams f ns ps) = mapM_ (elabDecl' pinfo) ps
@@ -293,15 +332,17 @@ elabDecl' info (PParams f ns ps) = mapM_ (elabDecl' pinfo) ps
294-- Also find deferred names in the term and their types
333-- Also find deferred names in the term and their types
296−build :: ElabInfo -> Bool -> PTerm -> Elab (Term, [(Name, Type)])
335+build :: IState -> ElabInfo -> Bool -> PTerm -> Elab (Term, [(Name, Type)])
336+build ist info pattern tm
297−build info pattern tm = do elab info pattern tm
337+ = do elab ist info pattern tm
298− tt <- get_term
338+ tt <- get_term
299− return $ runState (collectDeferred tt) []
339+ return $ runState (collectDeferred tt) []
301−elab :: ElabInfo -> Bool -> PTerm -> Elab ()
341+elab :: IState -> ElabInfo -> Bool -> PTerm -> Elab ()
302−elab info pattern tm = do elab' tm
342+elab ist info pattern tm
303− when pattern -- convert remaining holes to pattern vars
344+ when pattern -- convert remaining holes to pattern vars
306 isph arg = case getTm arg of
347 isph arg = case getTm arg of
307 Placeholder -> True
348 Placeholder -> True
@@ -309,13 +350,39 @@ elab info pattern tm = do elab' tm
310 toElab arg = case getTm arg of
351 toElab arg = case getTm arg of
311 Placeholder -> Nothing
352 Placeholder -> Nothing
312− v -> Just (elab' v)
353+ v -> Just (elabE v)
314 mkPat = do hs <- get_holes
355 mkPat = do hs <- get_holes
315 case hs of
356 case hs of
316 (h: hs) -> do patvar h; mkPat
357 (h: hs) -> do patvar h; mkPat
317 [] -> return ()
358 [] -> return ()
360+ -- Expand implict arguments here, then move on to main elaborator
362+-- | Just ps <- lookupCtxt n (inblock info)
363+-- = -- let exp = (PApp fc (PRef fc n) (map (pexp . (PRef fc)) ps))
364+-- elabE (PApp fc (PRef fc n) [])
365+-- elabE f@(PApp fc fn args) = trace ("Elaborating " ++ show f) $ elab' f
369+-- where elabN f False = let afn = aiFn ist fc f [] in
370+-- -- trace ("Ref expanded to " ++ showImp True afn) $
372+-- elabN f True = elab' (PRef fc f)
373+-- elabE (PApp fc fn@(PRef _ f) args)
375+-- elabApp f args l -- no implicits
376+-- where elabApp f args False = let afn = aiFn ist fc f args in
377+-- -- trace ("Expanded to " ++ showImp True afn) $
379+-- elabApp f args True = elab' (PApp fc fn args)
380+-- elabE (PApp fc f as) = elab' (mkPApp fc 1 f as)
383+ local f = do e <- get_env
384+ return (f `elem` map fst e)
319 elab' PSet = do fill (RSet 0); solve
386 elab' PSet = do fill (RSet 0); solve
320 elab' (PConstant c) = do apply (RConstant c) []; solve
387 elab' (PConstant c) = do apply (RConstant c) []; solve
321 elab' (PQuote r) = do fill r; solve
388 elab' (PQuote r) = do fill r; solve
@@ -327,9 +394,9 @@ elab info pattern tm = do elab' tm
327 elab' (PEq fc l r) = elab' (PApp fc (PRef fc eqTy) [pimp (MN 0 "a") Placeholder,
394 elab' (PEq fc l r) = elab' (PApp fc (PRef fc eqTy) [pimp (MN 0 "a") Placeholder,
328 pimp (MN 0 "b") Placeholder,
395 pimp (MN 0 "b") Placeholder,
329 pexp l, pexp r])
396 pexp l, pexp r])
330− elab' (PPair fc l r) = try (elab' (PApp fc (PRef fc pairTy)
397+ elab' (PPair fc l r) = try (elabE (PApp fc (PRef fc pairTy)
331 [pexp l,pexp r]))
398 [pexp l,pexp r]))
332− (elab' (PApp fc (PRef fc pairCon)
399+ (elabE (PApp fc (PRef fc pairCon)
333 [pimp (MN 0 "A") Placeholder,
400 [pimp (MN 0 "A") Placeholder,
334 pimp (MN 0 "B") Placeholder,
401 pimp (MN 0 "B") Placeholder,
335 pexp l, pexp r]))
402 pexp l, pexp r]))
@@ -352,21 +419,18 @@ elab info pattern tm = do elab' tm
352 where inparamBlock n = case lookupCtxt n (inblock info) of
419 where inparamBlock n = case lookupCtxt n (inblock info) of
353 Nothing -> False
420 Nothing -> False
354 _ -> True
421 _ -> True
356− | Just ps <- lookupCtxt n (inblock info)
357− = elab' (PApp fc (PRef fc n) [])
358− | otherwise = erun fc $ do apply (Var n) []; solve
422+ elab' (PRef fc n) = erun fc $ do apply (Var n) []; solve
359 elab' (PLam n Placeholder sc)
423 elab' (PLam n Placeholder sc)
360− = do attack; intro (Just n); elab' sc; solve
424+ = do attack; intro (Just n); elabE sc; solve
361 elab' (PPi _ n Placeholder sc)
425 elab' (PPi _ n Placeholder sc)
362− = do attack; arg n (MN 0 "ty"); elab' sc; solve
426+ = do attack; arg n (MN 0 "ty"); elabE sc; solve
363 elab' (PPi _ n ty sc)
427 elab' (PPi _ n ty sc)
364 = do attack; tyn <- unique_hole (MN 0 "ty")
428 = do attack; tyn <- unique_hole (MN 0 "ty")
365 claim tyn (RSet 0)
429 claim tyn (RSet 0)
366 forall n (Var tyn)
430 forall n (Var tyn)
367 focus tyn
431 focus tyn
368− elab' ty
432+ elabE ty
369− elab' sc
433+ elabE sc
371 elab' (PLet n Placeholder val sc)
435 elab' (PLet n Placeholder val sc)
372 = do attack; -- (h:_) <- get_holes
436 = do attack; -- (h:_) <- get_holes
@@ -377,29 +441,27 @@ elab info pattern tm = do elab' tm
377 claim valn (Var tyn)
441 claim valn (Var tyn)
378 letbind n (Var tyn) (Var valn)
442 letbind n (Var tyn) (Var valn)
379 focus valn
443 focus valn
380− elab' val
444+ elabE val
381− elab' sc
445+ elabE sc
382 -- end_unify
446 -- end_unify
384− elab' (PApp fc (PRef _ f) args)
448+ elab' (PApp fc (PRef _ f) args')
385− | Just ps <- lookupCtxt f (inblock info)
449+ = do let args = {- case lookupCtxt f (inblock info) of
387− elabApp (liftname info f) (map (pexp . (PRef fc)) ps ++ args)
450+ Just ps -> (map (pexp . (PRef fc)) ps ++ args')
388− | otherwise = erun fc $ elabApp f args
451+ _ ->-} args'
389− where elabApp f args
390− = try (do ns <- apply (Var f) (map isph args)
452+ try (do ns <- apply (Var f) (map isph args)
392− elabArgs ns (map (\x -> (lazyarg x, getTm x)) args))
454+ elabArgs ns (map (\x -> (lazyarg x, getTm x)) args))
393− (do apply_elab f (map toElab args)
455+ (do apply_elab f (map toElab args)
395 elab' (PApp fc f [arg])
457 elab' (PApp fc f [arg])
396 = erun fc $
458 = erun fc $
397− do simple_app (elab' f) (elab' (getTm arg))
459+ do simple_app (elabE f) (elabE (getTm arg))
399 elab' Placeholder = do (h : hs) <- get_holes
461 elab' Placeholder = do (h : hs) <- get_holes
400 movelast h
462 movelast h
401 elab' (PMetavar n) = do attack; defer n; solve
463 elab' (PMetavar n) = do attack; defer n; solve
402− elab' (PProof ts) = do mapM_ (runTac True) ts
464+ elab' (PProof ts) = do mapM_ (runTac True ist) ts
403 elab' (PElabError e) = fail e
465 elab' (PElabError e) = fail e
404 elab' x = fail $ "Not implemented " ++ show x
466 elab' x = fail $ "Not implemented " ++ show x
@@ -412,7 +474,7 @@ elab info pattern tm = do elab' tm
412 pexp t]);
474 pexp t]);
413 elabArgs ns args
475 elabArgs ns args
414 | otherwise
476 | otherwise
415− = do focus n; elab' t; elabArgs ns args
477+ = do focus n; elabE t; elabArgs ns args
418collectDeferred :: Term -> State [(Name, Type)] Term
480collectDeferred :: Term -> State [(Name, Type)] Term
@@ -433,16 +495,23 @@ collectDeferred t = return t
434-- Running tactics directly
496-- Running tactics directly
436−runTac :: Bool -> PTactic -> Elab ()
498+runTac :: Bool -> IState -> PTactic -> Elab ()
437−runTac autoSolve = runT where
499+runTac autoSolve ist tac = runT (fmap (addImpl ist) tac) where
438 runT (Intro []) = do g <- goal
500 runT (Intro []) = do g <- goal
439 attack; intro (bname g)
501 attack; intro (bname g)
441 bname (Bind n _ _) = Just n
503 bname (Bind n _ _) = Just n
442 bname _ = Nothing
504 bname _ = Nothing
443 runT (Intro xs) = mapM_ (\x -> do attack; intro (Just x)) xs
505 runT (Intro xs) = mapM_ (\x -> do attack; intro (Just x)) xs
444− runT (Exact tm) = do elab toplevel False tm
506+ runT (Exact tm) = do elab ist toplevel False tm
445 when autoSolve solveAll
507 when autoSolve solveAll
508+ runT (Refine fn []) = do let imps = case lookupCtxt fn (idris_implicits ist) of
510+ Just args -> map isImp args
511+ ns <- apply (Var fn) imps
512+ when autoSolve solveAll
513+ where isImp (PImp _ _ _) = True
446 runT (Refine fn imps) = do ns <- apply (Var fn) imps
515 runT (Refine fn imps) = do ns <- apply (Var fn) imps
447 when autoSolve solveAll
516 when autoSolve solveAll
448 runT (Rewrite tm) -- to elaborate tm, let bind it, then rewrite by that
517 runT (Rewrite tm) -- to elaborate tm, let bind it, then rewrite by that
@@ -455,17 +524,17 @@ runTac autoSolve = runT where
455 letn <- unique_hole (MN 0 "rewrite_rule")
524 letn <- unique_hole (MN 0 "rewrite_rule")
456 letbind letn (Var tyn) (Var valn)
525 letbind letn (Var tyn) (Var valn)
457 focus valn
526 focus valn
458− elab toplevel False tm
527+ elab ist toplevel False tm
459 rewrite (Var letn)
528 rewrite (Var letn)
460 when autoSolve solveAll
529 when autoSolve solveAll
461 runT Compute = compute
530 runT Compute = compute
462− runT Trivial = try (do elab toplevel False (PRefl (FC "prf" 0))
531+ runT Trivial = try (do elab ist toplevel False (PRefl (FC "prf" 0))
463 when autoSolve solveAll)
532 when autoSolve solveAll)
464 (do env <- get_env
533 (do env <- get_env
465 tryAll (map fst env))
534 tryAll (map fst env))
467 tryAll [] = fail "No trivial solution"
536 tryAll [] = fail "No trivial solution"
468− tryAll (x:xs) = try (do elab toplevel False (PRef (FC "prf" 0) x)
537+ tryAll (x:xs) = try (do elab ist toplevel False (PRef (FC "prf" 0) x)
469 when autoSolve solveAll)
538 when autoSolve solveAll)
470 (tryAll xs)
539 (tryAll xs)
471 runT (Focus n) = focus n
540 runT (Focus n) = focus n