@@ -538,8 +538,17 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
538538 -- Build the LHS as an "Infer", and pull out its type and
539539 -- pattern bindings
540540 i <- get
541− let lhs = addImplPat i lhs_in
541+ -- get the parameters first, to pass through to any where block
542+ let fn_ty = case lookupTy Nothing fname (tt_ctxt i) of
543+ [t] -> t
544+ _ -> error "Can't happen (elabClause function type)"
545+ let fn_is = case lookupCtxt Nothing fname (idris_implicits i) of
546+ [t] -> t
547+ _ -> []
548+ let params = getParamsInType i [] fn_is fn_ty
549+ let lhs = addImplPat i (propagateParams params lhs_in)
542550 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showImp True lhs)
551+ logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
543552 ((lhs', dlhs, []), _) <-
544553 tclift $ elaborate ctxt (MN 0 "patLHS") infP []
545554 (erun fc (buildTC i info True tcgen fname (infTerm lhs)))
@@ -631,6 +640,40 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
631640 -- _ -> MN i (show n)) . l
632641 }
633642
643+ getParamsInType i env (PExp _ _ _ _ : is) (Bind n (Pi t) sc)
644+ = getParamsInType i env is (instantiate (P Bound n t) sc)
645+ getParamsInType i env (_ : is) (Bind n (Pi t) sc)
646+ = getParamsInType i (n : env) is (instantiate (P Bound n t) sc)
647+ getParamsInType i env is tm@(App f a)
648+ | (P _ tn _, args) <- unApply tm
649+ = case lookupCtxt Nothing tn (idris_datatypes i) of
650+ [t] -> nub $ paramNames args env (param_pos t) ++
651+ getParamsInType i env is f ++
652+ getParamsInType i env is a
653+ [] -> nub $ getParamsInType i env is f ++
654+ getParamsInType i env is a
655+ | otherwise = nub $ getParamsInType i env is f ++
656+ getParamsInType i env is a
657+ getParamsInType i _ _ _ = []
658+
659+ paramNames args env [] = []
660+ paramNames args env (p : ps)
661+ | length args > p = case args!!p of
662+ P _ n _ -> if n `elem` env
663+ then n : paramNames args env ps
664+ else paramNames args env ps
665+ _ -> paramNames args env ps
666+ | otherwise = paramNames args env ps
667+
668+ propagateParams :: [Name] -> PTerm -> PTerm
669+ propagateParams ps (PApp _ (PRef fc n) args)
670+ = PApp fc (PRef fc n) (map addP args)
671+ where addP imp@(PImp _ _ _ Placeholder _)
672+ | pname imp `elem` ps = imp { getTm = PRef fc (pname imp) }
673+ addP t = t
674+ propagateParams ps (PRef fc n)
675+ = PApp fc (PRef fc n) (map (\x -> pimp x (PRef fc x)) ps)
676+
634677elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
635678 = do ctxt <- getContext
636679 -- Build the LHS as an "Infer", and pull out its type and
@@ -852,7 +895,7 @@ elabClass info syn doc fc constraints tn ps ds
852895 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
853896 let ds = map (decorateid defaultdec)
854897 [PTy "" syn fc [] n ty',
855− PClauses fc (TCGen:o ++ opts) n cs]
898+ PClauses fc (Inlinable:TCGen:o ++ opts) n cs]
856899 iLOG (show ds)
857900 return (n, ((defaultdec n, ds!!1), ds))
858901 _ -> fail $ show n ++ " is not a method"
@@ -981,7 +1024,7 @@ elabInstance info syn fc cs n ps t expn ds
9811024 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
9821025 show (concat (nub wparams))
9831026 let lhs = case concat (nub wparams) of
984− [] -> PRef fc iname
1027+ _ -> PRef fc iname
9851028 as -> PApp fc (PRef fc iname) as
9861029 let rhs = PApp fc (PRef fc (instanceName ci))
9871030 (map (pexp . mkMethApp) mtys)