@@ -538,8 +538,17 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
538 -- Build the LHS as an "Infer", and pull out its type and
538 -- Build the LHS as an "Infer", and pull out its type and
539 -- pattern bindings
539 -- pattern bindings
541+ -- get the parameters first, to pass through to any where block
542+ let fn_ty = case lookupTy Nothing fname (tt_ctxt i) of
544+ _ -> error "Can't happen (elabClause function type)"
545+ let fn_is = case lookupCtxt Nothing fname (idris_implicits i) of
548+ let params = getParamsInType i [] fn_is fn_ty
541− let lhs = addImplPat i lhs_in
549+ let lhs = addImplPat i (propagateParams params lhs_in)
542 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showImp True lhs)
550 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showImp True lhs)
551+ logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
543 ((lhs', dlhs, []), _) <-
552 ((lhs', dlhs, []), _) <-
544 tclift $ elaborate ctxt (MN 0 "patLHS") infP []
553 tclift $ elaborate ctxt (MN 0 "patLHS") infP []
545 (erun fc (buildTC i info True tcgen fname (infTerm lhs)))
554 (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)
631 -- _ -> MN i (show n)) . l
640 -- _ -> MN i (show n)) . l
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 _ _ _ = []
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
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) }
674+ propagateParams ps (PRef fc n)
675+ = PApp fc (PRef fc n) (map (\x -> pimp x (PRef fc x)) ps)
634elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
677elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
635 = do ctxt <- getContext
678 = do ctxt <- getContext
636 -- Build the LHS as an "Infer", and pull out its type and
679 -- 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
852 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
895 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
853 let ds = map (decorateid defaultdec)
896 let ds = map (decorateid defaultdec)
854 [PTy "" syn fc [] n ty',
897 [PTy "" syn fc [] n ty',
855− PClauses fc (TCGen:o ++ opts) n cs]
898+ PClauses fc (Inlinable:TCGen:o ++ opts) n cs]
856 iLOG (show ds)
899 iLOG (show ds)
857 return (n, ((defaultdec n, ds!!1), ds))
900 return (n, ((defaultdec n, ds!!1), ds))
858 _ -> fail $ show n ++ " is not a method"
901 _ -> fail $ show n ++ " is not a method"
@@ -981,7 +1024,7 @@ elabInstance info syn fc cs n ps t expn ds
981 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
1024 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
982 show (concat (nub wparams))
1025 show (concat (nub wparams))
983 let lhs = case concat (nub wparams) of
1026 let lhs = case concat (nub wparams) of
984− [] -> PRef fc iname
1027+ _ -> PRef fc iname
985 as -> PApp fc (PRef fc iname) as
1028 as -> PApp fc (PRef fc iname) as
986 let rhs = PApp fc (PRef fc (instanceName ci))
1029 let rhs = PApp fc (PRef fc (instanceName ci))
987 (map (pexp . mkMethApp) mtys)
1030 (map (pexp . mkMethApp) mtys)