@@ -62,10 +62,10 @@ elabInterface :: ElabInfo
62 -> SyntaxInfo
62 -> SyntaxInfo
63 -> Docstring (Either Err PTerm)
63 -> Docstring (Either Err PTerm)
65− -> [(Name, PTerm)]
65+ -> [(Name, PTerm)] -- ^ Superclass constraints
68− -> [(Name, FC, PTerm)]
68+ -> [(Name, FC, PTerm)] -- ^ Parameters
69 -> [(Name, Docstring (Either Err PTerm))]
69 -> [(Name, Docstring (Either Err PTerm))]
70 -> [(Name, FC)] -- ^ determining params
70 -> [(Name, FC)] -- ^ determining params
71 -> [PDecl] -- ^ interface body
71 -> [PDecl] -- ^ interface body
@@ -74,7 +74,6 @@ elabInterface :: ElabInfo
74 -> Idris ()
74 -> Idris ()
75elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
75elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
76 = do let cn = fromMaybe (SN (ImplementationCtorN tn)) (fst <$> mcn)
76 = do let cn = fromMaybe (SN (ImplementationCtorN tn)) (fst <$> mcn)
77− let tty = pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
78 let constraint = PApp fc (PRef fc [] tn)
77 let constraint = PApp fc (PRef fc [] tn)
79 (map (pexp . PRef fc []) (map (\(n, _, _) -> n) ps))
78 (map (pexp . PRef fc []) (map (\(n, _, _) -> n) ps))
@@ -82,6 +81,20 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
82 syn_in { using = addToUsing (using syn_in)
81 syn_in { using = addToUsing (using syn_in)
83 [(pn, pt) | (pn, _, pt) <- ps]
82 [(pn, pt) | (pn, _, pt) <- ps]
85+ -- Calculate implicit parameters
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
93+ let tty = impbind (map (\(n, _, ty) -> (n, ty)) impps) $
94+ pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
96+ logElab 5 $ "Implicit parameters are " ++ show impps
97+ logElab 5 $ "Interface type is " ++ showTmImpls tty
86 -- build data declaration
99 -- build data declaration
87 let mdecls = filter tydecl ds -- method declarations
100 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
95 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
108 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
97 logElab 2 $ "Building methods " ++ show mnames
110 logElab 2 $ "Building methods " ++ show mnames
98− ims <- mapM (tdecl mnames) mdecls
111+ ims <- mapM (tdecl impps mnames) mdecls
99 defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
112 defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
100 (filter clause ds)
113 (filter clause ds)
101 let (methods, imethods)
114 let (methods, imethods)
@@ -103,20 +116,23 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
103 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
116 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
105 -- build implementation constructor type
118 -- 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
107 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
120 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
108 constraint
121 constraint
110 let cons = [(cd, pDocs ++ mapMaybe memberDocs ds, cn, NoFC, cty, fc, [])]
123 let cons = [(cd, pDocs ++ mapMaybe memberDocs ds, cn, NoFC, cty, fc, [])]
111 let ddecl = PDatadecl tn NoFC tty cons
124 let ddecl = PDatadecl tn NoFC tty cons
113− logElab 5 $ "Interface data " ++ show (showDImp verbosePPOption ddecl)
126+ logElab 5 $ "Interface " ++ show (showDImp verbosePPOption ddecl)
115 -- Elaborate the data declaration
128 -- Elaborate the data declaration
116 elabData info (syn { no_imp = no_imp syn ++ mnames,
129 elabData info (syn { no_imp = no_imp syn ++ mnames,
117 imp_methods = mnames }) doc pDocs fc [] ddecl
130 imp_methods = mnames }) doc pDocs fc [] ddecl
118 dets <- findDets cn (map fst fds)
131 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)
121 -- for each constraint, build a top level function to chase it
137 -- for each constraint, build a top level function to chase it
122 cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
138 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
188 getMName (PTy _ _ _ _ _ n nfc _) = nsroot n
204 getMName (PTy _ _ _ _ _ n nfc _) = nsroot n
189 getMName (PData _ _ _ _ _ (PLaterdecl n nfc _)) = nsroot n
205 getMName (PData _ _ _ _ _ (PLaterdecl n nfc _)) = nsroot n
191− tdecl allmeths (PTy doc _ syn _ o n nfc t)
207+ tdecl impps allmeths (PTy doc _ syn _ o n nfc t)
192− = do t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
208+ = do t' <- implicit' info syn (map (\(n, _, _) -> n) (impps ++ ps) ++ allmeths) n t
193 logElab 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
209 logElab 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
194 return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
210 return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
195 (n, (False, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
211 (n, (False, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
196 (\ l s p -> Imp l s p Nothing True) t'))),
212 (\ l s p -> Imp l s p Nothing True) t'))),
197 (n, (nfc, syn, o, t) ) )
213 (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))
199 = do let o = []
215 = do let o = []
200 t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
216 t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
201 logElab 2 $ "Data method " ++ show n ++ " : " ++ showTmImpls t'
217 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
203 (n, (True, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
219 (n, (True, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
204 (\ l s p -> Imp l s p Nothing True) t'))),
220 (\ l s p -> Imp l s p Nothing True) t'))),
205 (n, (nfc, syn, o, t) ) )
221 (n, (nfc, syn, o, t) ) )
206− tdecl allmeths (PData doc _ syn _ _ _)
222+ tdecl impps allmeths (PData doc _ syn _ _ _)
207 = ierror $ At fc (Msg "Data definitions not allowed in an interface declaration")
223 = 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")
210 -- Create default definitions
226 -- Create default definitions
211 defdecl mtys c d@(PClauses fc opts n cs) =
227 defdecl mtys c d@(PClauses fc opts n cs) =