@@ -22,7 +22,7 @@ defaultOpts = IOption 0
23data IState = IState { tt_ctxt :: Context,
23data IState = IState { tt_ctxt :: Context,
24 idris_infixes :: [FixDecl],
24 idris_infixes :: [FixDecl],
25− idris_implicits :: Ctxt [Name],
25+ idris_implicits :: Ctxt ([Name], Int), -- implicits, arity
26 idris_log :: String,
26 idris_log :: String,
27 idris_options :: IOption
27 idris_options :: IOption
@@ -237,6 +237,7 @@ infP = P (TCon 0) inferTy (Set 0)
237getInferTerm, getInferType :: Term -> Term
237getInferTerm, getInferType :: Term -> Term
238getInferTerm (Bind n b sc) = Bind n b $ getInferTerm sc
238getInferTerm (Bind n b sc) = Bind n b $ getInferTerm sc
239getInferTerm (App (App _ _) tm) = tm
239getInferTerm (App (App _ _) tm) = tm
240+getInferTerm tm = error ("getInferTerm " ++ show tm)
241getInferType (Bind n b sc) = Bind n b $ getInferType sc
242getInferType (Bind n b sc) = Bind n b $ getInferType sc
242getInferType (App (App _ ty) _) = ty
243getInferType (App (App _ ty) _) = ty
@@ -247,23 +248,25 @@ getInferType (App (App _ ty) _) = ty
247-- Add implicit Pi bindings for any names in the term which appear in an
248-- Add implicit Pi bindings for any names in the term which appear in an
248-- argument position.
249-- argument position.
250−implicitise :: IState -> PTerm -> (PTerm, [Name])
251+implicitise :: IState -> PTerm -> (PTerm, ([Name], Int))
251implicitise ist tm
252implicitise ist tm
252− = let (declimps, ns) = execState (imps [] tm) ([], []) in
253+ = let (declimps, a, ns) = execState (imps [] tm) ([], 0, []) in
253− (pibind ns tm, ns ++ reverse declimps)
254+ (pibind ns tm, (ns ++ reverse declimps, a))
255 imps env (PApp f is es)
256 imps env (PApp f is es)
256− = do (decls, ns) <- get
257+ = do (decls, a, ns) <- get
257 let isn = concatMap (namesIn ist) (map snd is)
258 let isn = concatMap (namesIn ist) (map snd is)
258 let esn = concatMap (namesIn ist) es
259 let esn = concatMap (namesIn ist) es
259− put (decls, nub (ns ++ ((isn ++ esn) \\ env)))
260+ put (decls, a, nub (ns ++ ((isn ++ esn) \\ env)))
260 imps env (PPi Imp n ty sc)
261 imps env (PPi Imp n ty sc)
261 = do imps env ty
262 = do imps env ty
262− (decls, ns) <- get
263+ (impdecls, a, ns) <- get
263− put (n:decls, ns)
264+ put (n:impdecls, a+1, ns)
264 imps (n:env) sc
265 imps (n:env) sc
265 imps env (PPi Exp n ty sc)
266 imps env (PPi Exp n ty sc)
266 = do imps env ty
267 = do imps env ty
268+ (impdecls, a, ns) <- get
269+ put (impdecls, a+1, ns)
267 imps (n:env) sc
270 imps (n:env) sc
268 imps env (PLam n ty sc)
271 imps env (PLam n ty sc)
269 = do imps env ty
272 = do imps env ty
@@ -297,12 +300,16 @@ addImpl ist ptm = ai [] ptm
298 aiFn env (PRef f) is es | not (f `elem` env)
301 aiFn env (PRef f) is es | not (f `elem` env)
299 = case lookupCtxt f (idris_implicits ist) of
302 = case lookupCtxt f (idris_implicits ist) of
300− Just ns -> pApp (PRef f) (insertImpl ns is) es
303+ Just (ns, a) -> pApp a (PRef f) (insertImpl ns is) es
301− Nothing -> pApp (PRef f) is es
304+ Nothing -> pApp 1 (PRef f) is es
302− aiFn env f is es = pApp f is es
305+ aiFn env f is es = pApp 1 f is es
304− pApp f [] [] = f
307+ pApp a f [] [] = f
308+ pApp a f is es = let rest = drop a es in
305− pApp f is es = PApp f is es
309+ appRest (PApp f is (take a es)) rest
312+ appRest f (a : as) = appRest (PApp f [] [a]) as
307 insertImpl [] given = []
314 insertImpl [] given = []
308 insertImpl (n:ns) given
315 insertImpl (n:ns) given