@@ -106,6 +106,12 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
106 concatMap (namesIn [] ist) (map snd constraints)
106 concatMap (namesIn [] ist) (map snd constraints)
108 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
108 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
110+ let pre_ddecl = PLaterdecl tn NoFC tty
111+ -- Elaborate the interface header
112+ elabData info (syn { no_imp = no_imp syn ++ mnames,
113+ imp_methods = mnames }) doc pDocs fc [] pre_ddecl
114+ dets <- findDets tn (map fst fds)
110 logElab 2 $ "Building methods " ++ show mnames
116 logElab 2 $ "Building methods " ++ show mnames
111 ims <- mapM (tdecl impps mnames) mdecls
117 ims <- mapM (tdecl impps mnames) mdecls
@@ -114,7 +120,20 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
114 let (methods, imethods)
120 let (methods, imethods)
115 = unzip (map (\ (x, y, z) -> (x, y)) ims)
121 = unzip (map (\ (x, y, z) -> (x, y)) ims)
116 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
122 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
124+ addInterface tn (CI cn (map nodoc imethods) defaults idecls
125+ (map (\(n, _, _) -> n) impps)
126+ (map (\(n, _, _) -> n) ps)
127+ (map snd constraints)
130+ -- for each constraint, build a top level function to chase it
131+ -- elaborate types now, bodies later (after we've done the constructor
132+ -- of the interface)
133+ cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
134+ let (cfnTyDecls, cfnDefs) = unzip cfns
135+ mapM_ (rec_elabDecl info EAll info) cfnTyDecls
118 -- build implementation constructor type
137 -- build implementation constructor type
119 let cty = impbind [(pn, pt) | (pn, _, pt) <- impps ++ ps] $ conbind constraints
138 let cty = impbind [(pn, pt) | (pn, _, pt) <- impps ++ ps] $ conbind constraints
120 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
139 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
@@ -125,26 +144,27 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
126 logElab 5 $ "Interface " ++ show (showDImp verbosePPOption ddecl)
145 logElab 5 $ "Interface " ++ show (showDImp verbosePPOption ddecl)
147+ -- for each method, build a top level function
148+ -- 'tfun' builds appropriate implicits for the constructor
150+ fns <- mapM (tfun cn constraint (syn { imp_methods = mnames }) -- mnames })
151+ (map fst imethods)) imethods
152+ let (fnTyDecls, fnDefs) = unzip fns
128 -- Elaborate the data declaration
154 -- Elaborate the data declaration
129 elabData info (syn { no_imp = no_imp syn ++ mnames,
155 elabData info (syn { no_imp = no_imp syn ++ mnames,
130 imp_methods = mnames }) doc pDocs fc [] ddecl
156 imp_methods = mnames }) doc pDocs fc [] ddecl
131− dets <- findDets cn (map fst fds)
132− addInterface tn (CI cn (map nodoc imethods) defaults idecls
133− (map (\(n, _, _) -> n) impps)
134− (map (\(n, _, _) -> n) ps)
135− (map snd constraints)
138− -- for each constraint, build a top level function to chase it
139− cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
140− mapM_ (rec_elabDecl info EAll info) (concat cfns)
158+ mapM_ (rec_elabDecl info EAll info) fnTyDecls
142− -- for each method, build a top level function
160+ logElab 5 $ "Function types " ++ show fnTyDecls
143− fns <- mapM (tfun cn constraint (syn { imp_methods = mnames })
161+ logElab 5 $ "Method types now: " ++ show imethods
144− (map fst imethods)) imethods
162+
145− logElab 5 $ "Functions " ++ show fns
163+ -- Elaborate the the top level constraint chasers
146− -- Elaborate the the top level methods
164+ -- (Types elaborated earlier)
165+ mapM_ (rec_elabDecl info EAll info) cfnDefs
166+ -- Elaborate the the top level method bodies
147− mapM_ (rec_elabDecl info EAll info) (concat fns)
167+ mapM_ (rec_elabDecl info EAll info) fnDefs
149 -- Flag all the top level data declarations as injective
169 -- Flag all the top level data declarations as injective
150 mapM_ (\n -> do setInjectivity n True
170 mapM_ (\n -> do setInjectivity n True
@@ -207,7 +227,7 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
208 tdecl impps allmeths (PTy doc _ syn _ o n nfc t)
228 tdecl impps allmeths (PTy doc _ syn _ o n nfc t)
209 = do t' <- implicit' info syn (map (\(n, _, _) -> n) (impps ++ ps) ++ allmeths) n t
229 = do t' <- implicit' info syn (map (\(n, _, _) -> n) (impps ++ ps) ++ allmeths) n t
210− logElab 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
230+ logElab 1 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
211 return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
231 return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
212 (n, (False, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
232 (n, (False, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
213 (\ l s p r -> Imp l s p Nothing True r) t'))),
233 (\ l s p r -> Imp l s p Nothing True r) t'))),
@@ -249,7 +269,7 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
249 clause _ = False
269 clause _ = False
251 -- Generate a function for chasing a dictionary constraint
271 -- Generate a function for chasing a dictionary constraint
252− cfun :: Name -> PTerm -> SyntaxInfo -> [a] -> (Name, PTerm) -> Idris [PDecl' PTerm]
272+ cfun :: Name -> PTerm -> SyntaxInfo -> [a] -> (Name, PTerm) -> Idris (PDecl, PDecl)
253 cfun cn c syn all (cnm, con)
273 cfun cn c syn all (cnm, con)
254 = do let cfn = SN (ParentN cn (txt (show con)))
274 = do let cfn = SN (ParentN cn (txt (show con)))
255 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
275 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
@@ -269,8 +289,8 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
269 addImplementation False True conn' cfn
289 addImplementation False True conn' cfn
270 addIBC (IBCImplementation False True conn' cfn)
290 addIBC (IBCImplementation False True conn' cfn)
271-- iputStrLn ("Added " ++ show (conn, cfn, ty))
291-- iputStrLn ("Added " ++ show (conn, cfn, ty))
272− return [PTy emptyDocstring [] syn fc [] cfn NoFC ty,
292+ return (PTy emptyDocstring [] syn fc [] cfn NoFC ty,
273− PClauses fc [Inlinable, Dictionary] cfn [PClause fc cfn lhs [] rhs []]]
293+ PClauses fc [Inlinable, Dictionary] cfn [PClause fc cfn lhs [] rhs []])
275 -- | Generate a top level function which looks up a method in a given
295 -- | Generate a top level function which looks up a method in a given
276 -- dictionary (this is inlinable, always)
296 -- dictionary (this is inlinable, always)
@@ -279,7 +299,7 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
279 -> SyntaxInfo -> [Name] -- ^ All the method names
299 -> SyntaxInfo -> [Name] -- ^ All the method names
280 -> (Name, (Bool, FC, Docstring (Either Err PTerm), FnOpts, PTerm))
300 -> (Name, (Bool, FC, Docstring (Either Err PTerm), FnOpts, PTerm))
281 -- ^ The present declaration
301 -- ^ The present declaration
282− -> Idris [PDecl]
302+ -> Idris (PDecl, PDecl)
283 tfun cn c syn all (m, (isdata, mfc, doc, o, ty))
303 tfun cn c syn all (m, (isdata, mfc, doc, o, ty))
284 = do let ty' = expandMethNS syn (insertConstraint c all ty)
304 = do let ty' = expandMethNS syn (insertConstraint c all ty)
285 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
305 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
@@ -291,8 +311,15 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
291 logElab 2 ("Top level type: " ++ showTmImpls ty')
311 logElab 2 ("Top level type: " ++ showTmImpls ty')
292 logElab 1 (show (m, ty', capp, margs))
312 logElab 1 (show (m, ty', capp, margs))
293 logElab 2 ("Definition: " ++ showTmImpls lhs ++ " = " ++ showTmImpls rhs)
313 logElab 2 ("Definition: " ++ showTmImpls lhs ++ " = " ++ showTmImpls rhs)
294− return [PTy doc [] syn fc o m mfc ty',
314+ return (PTy doc [] syn fc o m mfc ty',
295− PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []]]
315+ PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []])
317+ updateIMethod :: [(Name, PTerm)] ->
318+ (Name, (a, b, c, d, PTerm)) ->
319+ (Name, (a, b, c, d, PTerm))
320+ updateIMethod ns tm@(n, (isf, mfc, doc, o, ty))
321+ | Just ty' <- lookup (nsroot n) ns = (n, (isf, mfc, doc, o, ty'))
297 getMArgs (PPi (Imp _ _ _ _ _ _) n _ ty sc) = IA n : getMArgs sc
324 getMArgs (PPi (Imp _ _ _ _ _ _) n _ ty sc) = IA n : getMArgs sc
298 getMArgs (PPi (Exp _ _ _ _) n _ ty sc) = EA n : getMArgs sc
325 getMArgs (PPi (Exp _ _ _ _) n _ ty sc) = EA n : getMArgs sc