@@ -22,7 +22,7 @@ defaultOpts = IOption 0
2222
2323data IState = IState { tt_ctxt :: Context,
2424 idris_infixes :: [FixDecl],
25− idris_implicits :: Ctxt [Name],
25+ idris_implicits :: Ctxt ([Name], Int), -- implicits, arity
2626 idris_log :: String,
2727 idris_options :: IOption
2828 }
@@ -237,6 +237,7 @@ infP = P (TCon 0) inferTy (Set 0)
237237getInferTerm, getInferType :: Term -> Term
238238getInferTerm (Bind n b sc) = Bind n b $ getInferTerm sc
239239getInferTerm (App (App _ _) tm) = tm
240+getInferTerm tm = error ("getInferTerm " ++ show tm)
240241
241242getInferType (Bind n b sc) = Bind n b $ getInferType sc
242243getInferType (App (App _ ty) _) = ty
@@ -247,23 +248,25 @@ getInferType (App (App _ ty) _) = ty
247248-- Add implicit Pi bindings for any names in the term which appear in an
248249-- argument position.
249250
250−implicitise :: IState -> PTerm -> (PTerm, [Name])
251+implicitise :: IState -> PTerm -> (PTerm, ([Name], Int))
251252implicitise ist tm
252− = let (declimps, ns) = execState (imps [] tm) ([], []) in
253− (pibind ns tm, ns ++ reverse declimps)
253+ = let (declimps, a, ns) = execState (imps [] tm) ([], 0, []) in
254+ (pibind ns tm, (ns ++ reverse declimps, a))
254255 where
255256 imps env (PApp f is es)
256− = do (decls, ns) <- get
257+ = do (decls, a, ns) <- get
257258 let isn = concatMap (namesIn ist) (map snd is)
258259 let esn = concatMap (namesIn ist) es
259− put (decls, nub (ns ++ ((isn ++ esn) \\ env)))
260+ put (decls, a, nub (ns ++ ((isn ++ esn) \\ env)))
260261 imps env (PPi Imp n ty sc)
261262 = do imps env ty
262− (decls, ns) <- get
263− put (n:decls, ns)
263+ (impdecls, a, ns) <- get
264+ put (n:impdecls, a+1, ns)
264265 imps (n:env) sc
265266 imps env (PPi Exp n ty sc)
266267 = do imps env ty
268+ (impdecls, a, ns) <- get
269+ put (impdecls, a+1, ns)
267270 imps (n:env) sc
268271 imps env (PLam n ty sc)
269272 = do imps env ty
@@ -297,12 +300,16 @@ addImpl ist ptm = ai [] ptm
297300
298301 aiFn env (PRef f) is es | not (f `elem` env)
299302 = case lookupCtxt f (idris_implicits ist) of
300− Just ns -> pApp (PRef f) (insertImpl ns is) es
301− Nothing -> pApp (PRef f) is es
302− aiFn env f is es = pApp f is es
303+ Just (ns, a) -> pApp a (PRef f) (insertImpl ns is) es
304+ Nothing -> pApp 1 (PRef f) is es
305+ aiFn env f is es = pApp 1 f is es
303306
304− pApp f [] [] = f
305− pApp f is es = PApp f is es
307+ pApp a f [] [] = f
308+ pApp a f is es = let rest = drop a es in
309+ appRest (PApp f is (take a es)) rest
310+
311+ appRest f [] = f
312+ appRest f (a : as) = appRest (PApp f [] [a]) as
306313
307314 insertImpl [] given = []
308315 insertImpl (n:ns) given