@@ -62,10 +62,10 @@ elabInterface :: ElabInfo
6262 -> SyntaxInfo
6363 -> Docstring (Either Err PTerm)
6464 -> FC
65− -> [(Name, PTerm)]
65+ -> [(Name, PTerm)] -- ^ Superclass constraints
6666 -> Name
6767 -> FC
68− -> [(Name, FC, PTerm)]
68+ -> [(Name, FC, PTerm)] -- ^ Parameters
6969 -> [(Name, Docstring (Either Err PTerm))]
7070 -> [(Name, FC)] -- ^ determining params
7171 -> [PDecl] -- ^ interface body
@@ -74,7 +74,6 @@ elabInterface :: ElabInfo
7474 -> Idris ()
7575elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
7676 = do let cn = fromMaybe (SN (ImplementationCtorN tn)) (fst <$> mcn)
77− let tty = pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
7877 let constraint = PApp fc (PRef fc [] tn)
7978 (map (pexp . PRef fc []) (map (\(n, _, _) -> n) ps))
8079
@@ -82,6 +81,20 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
8281 syn_in { using = addToUsing (using syn_in)
8382 [(pn, pt) | (pn, _, pt) <- ps]
8483 }
84+
85+ -- Calculate implicit parameters
86+ ist <- getIState
87+ let impps_ns = nub $ map (\n -> (n, emptyFC, Placeholder)) $
88+ concatMap (implicitNamesIn [] ist)
89+ (map (\ (_,_,x) -> x) ps)
90+ let impps = filter (\ (n, _, _) ->
91+ n `notElem` (map (\ (n, _, _) -> n) ps)) impps_ns
92+
93+ let tty = impbind (map (\(n, _, ty) -> (n, ty)) impps) $
94+ pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
95+
96+ logElab 5 $ "Implicit parameters are " ++ show impps
97+ logElab 5 $ "Interface type is " ++ showTmImpls tty
8598
8699 -- build data declaration
87100 let mdecls = filter tydecl ds -- method declarations
@@ -95,7 +108,7 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
95108 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
96109
97110 logElab 2 $ "Building methods " ++ show mnames
98− ims <- mapM (tdecl mnames) mdecls
111+ ims <- mapM (tdecl impps mnames) mdecls
99112 defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
100113 (filter clause ds)
101114 let (methods, imethods)
@@ -103,20 +116,23 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
103116 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
104117
105118 -- build implementation constructor type
106− let cty = impbind [(pn, pt) | (pn, _, pt) <- ps] $ conbind constraints
119+ let cty = impbind [(pn, pt) | (pn, _, pt) <- impps ++ ps] $ conbind constraints
107120 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
108121 constraint
109122
110123 let cons = [(cd, pDocs ++ mapMaybe memberDocs ds, cn, NoFC, cty, fc, [])]
111124 let ddecl = PDatadecl tn NoFC tty cons
112125
113− logElab 5 $ "Interface data " ++ show (showDImp verbosePPOption ddecl)
126+ logElab 5 $ "Interface " ++ show (showDImp verbosePPOption ddecl)
114127
115128 -- Elaborate the data declaration
116129 elabData info (syn { no_imp = no_imp syn ++ mnames,
117130 imp_methods = mnames }) doc pDocs fc [] ddecl
118131 dets <- findDets cn (map fst fds)
119− addInterface tn (CI cn (map nodoc imethods) defaults idecls (map (\(n, _, _) -> n) ps) [] dets)
132+ addInterface tn (CI cn (map nodoc imethods) defaults idecls
133+ (map (\(n, _, _) -> n) impps)
134+ (map (\(n, _, _) -> n) ps)
135+ [] dets)
120136
121137 -- for each constraint, build a top level function to chase it
122138 cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
@@ -188,14 +204,14 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
188204 getMName (PTy _ _ _ _ _ n nfc _) = nsroot n
189205 getMName (PData _ _ _ _ _ (PLaterdecl n nfc _)) = nsroot n
190206
191− tdecl allmeths (PTy doc _ syn _ o n nfc t)
192− = do t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
207+ tdecl impps allmeths (PTy doc _ syn _ o n nfc t)
208+ = do t' <- implicit' info syn (map (\(n, _, _) -> n) (impps ++ ps) ++ allmeths) n t
193209 logElab 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
194210 return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
195211 (n, (False, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
196212 (\ l s p -> Imp l s p Nothing True) t'))),
197213 (n, (nfc, syn, o, t) ) )
198− tdecl allmeths (PData doc _ syn _ _ (PLaterdecl n nfc t))
214+ tdecl impps allmeths (PData doc _ syn _ _ (PLaterdecl n nfc t))
199215 = do let o = []
200216 t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
201217 logElab 2 $ "Data method " ++ show n ++ " : " ++ showTmImpls t'
@@ -203,9 +219,9 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
203219 (n, (True, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
204220 (\ l s p -> Imp l s p Nothing True) t'))),
205221 (n, (nfc, syn, o, t) ) )
206− tdecl allmeths (PData doc _ syn _ _ _)
222+ tdecl impps allmeths (PData doc _ syn _ _ _)
207223 = ierror $ At fc (Msg "Data definitions not allowed in an interface declaration")
208− tdecl _ _ = ierror $ At fc (Msg "Not allowed in an interface declaration")
224+ tdecl _ _ _ = ierror $ At fc (Msg "Not allowed in an interface declaration")
209225
210226 -- Create default definitions
211227 defdecl mtys c d@(PClauses fc opts n cs) =