@@ -50,12 +50,13 @@ import Data.List.Split (splitOn)
51import Util.Pretty(pretty, text)
51import Util.Pretty(pretty, text)
53−data MArgTy = IA | EA | CA deriving Show
53+data MArgTy = IA Name | EA Name | CA deriving Show
55elabClass :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
55elabClass :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
56 FC -> [(Name, PTerm)] ->
56 FC -> [(Name, PTerm)] ->
57− Name -> [(Name, PTerm)] -> [(Name, Docstring (Either Err PTerm))] -> [PDecl] -> Idris ()
57+ Name -> [(Name, PTerm)] -> [(Name, Docstring (Either Err PTerm))] ->
58+ [Name] -> [PDecl] -> Idris ()
58−elabClass info syn_in doc fc constraints tn ps pDocs ds
59+elabClass info syn_in doc fc constraints tn ps pDocs fds ds
59 = do let cn = SN (InstanceCtorN tn) -- sUN ("instance" ++ show tn) -- MN 0 ("instance" ++ show tn)
60 = do let cn = SN (InstanceCtorN tn) -- sUN ("instance" ++ show tn) -- MN 0 ("instance" ++ show tn)
60 let tty = pibind ps PType
61 let tty = pibind ps PType
61 let constraint = PApp fc (PRef fc tn)
62 let constraint = PApp fc (PRef fc tn)
@@ -75,7 +76,6 @@ elabClass info syn_in doc fc constraints tn ps pDocs ds
75 let (methods, imethods)
76 let (methods, imethods)
76 = unzip (map (\ ( x,y,z) -> (x, y)) ims)
77 = unzip (map (\ ( x,y,z) -> (x, y)) ims)
77 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
78 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
78− addClass tn (CI cn (map nodoc imethods) defaults idecls (map fst ps) [])
79 -- build instance constructor type
79 -- build instance constructor type
80 -- decorate names of functions to ensure they can't be referred
80 -- decorate names of functions to ensure they can't be referred
81 -- to elsewhere in the class declaration
81 -- to elsewhere in the class declaration
@@ -86,6 +86,9 @@ elabClass info syn_in doc fc constraints tn ps pDocs ds
86 let ddecl = PDatadecl tn tty cons
86 let ddecl = PDatadecl tn tty cons
87 logLvl 5 $ "Class data " ++ show (showDImp verbosePPOption ddecl)
87 logLvl 5 $ "Class data " ++ show (showDImp verbosePPOption ddecl)
88 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc pDocs fc [] ddecl
88 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc pDocs fc [] ddecl
90+ dets <- findDets cn fds
91+ addClass tn (CI cn (map nodoc imethods) defaults idecls (map fst ps) [] dets)
89 -- for each constraint, build a top level function to chase it
92 -- for each constraint, build a top level function to chase it
90 logLvl 5 $ "Building functions"
93 logLvl 5 $ "Building functions"
91-- let usyn = syn { using = map (\ (x,y) -> UImplicit x y) ps
94-- let usyn = syn { using = map (\ (x,y) -> UImplicit x y) ps
@@ -94,6 +97,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs ds
94 mapM_ (rec_elabDecl info EAll info) (concat fns)
97 mapM_ (rec_elabDecl info EAll info) (concat fns)
95 -- for each method, build a top level function
98 -- for each method, build a top level function
96 fns <- mapM (tfun cn constraint syn (map fst imethods)) imethods
99 fns <- mapM (tfun cn constraint syn (map fst imethods)) imethods
100+ logLvl 5 $ "Functions " ++ show fns
97 mapM_ (rec_elabDecl info EAll info) (concat fns)
101 mapM_ (rec_elabDecl info EAll info) (concat fns)
98 -- add the default definitions
102 -- add the default definitions
99 mapM_ (rec_elabDecl info EAll info) (concat (map (snd.snd) defs))
103 mapM_ (rec_elabDecl info EAll info) (concat (map (snd.snd) defs))
@@ -201,21 +205,21 @@ elabClass info syn_in doc fc constraints tn ps pDocs ds
201 return [PTy doc [] syn fc o m ty',
205 return [PTy doc [] syn fc o m ty',
202 PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []]]
206 PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []]]
204− getMArgs (PPi (Imp _ _ _ _) n ty sc) = IA : getMArgs sc
208+ getMArgs (PPi (Imp _ _ _ _) n ty sc) = IA n : getMArgs sc
205− getMArgs (PPi (Exp _ _ _) n ty sc) = EA : getMArgs sc
209+ getMArgs (PPi (Exp _ _ _) n ty sc) = EA n : getMArgs sc
206 getMArgs (PPi (Constraint _ _) n ty sc) = CA : getMArgs sc
210 getMArgs (PPi (Constraint _ _) n ty sc) = CA : getMArgs sc
207 getMArgs _ = []
211 getMArgs _ = []
209 getMeth (m:ms) (a:as) x | x == a = PRef fc m
213 getMeth (m:ms) (a:as) x | x == a = PRef fc m
210 | otherwise = getMeth ms as x
214 | otherwise = getMeth ms as x
212− lhsArgs (EA : xs) (n : ns) = [] -- pexp (PRef fc n) : lhsArgs xs ns
216+ lhsArgs (EA _ : xs) (n : ns) = [] -- pexp (PRef fc n) : lhsArgs xs ns
213− lhsArgs (IA : xs) ns = lhsArgs xs ns
217+ lhsArgs (IA n : xs) ns = pimp n (PRef fc n) False : lhsArgs xs ns
214 lhsArgs (CA : xs) ns = lhsArgs xs ns
218 lhsArgs (CA : xs) ns = lhsArgs xs ns
215 lhsArgs [] _ = []
219 lhsArgs [] _ = []
217− rhsArgs (EA : xs) (n : ns) = [] -- pexp (PRef fc n) : rhsArgs xs ns
221+ rhsArgs (EA _ : xs) (n : ns) = [] -- pexp (PRef fc n) : rhsArgs xs ns
218− rhsArgs (IA : xs) ns = pexp Placeholder : rhsArgs xs ns
222+ rhsArgs (IA n : xs) ns = pexp (PRef fc n) : rhsArgs xs ns
219 rhsArgs (CA : xs) ns = pconst (PResolveTC fc) : rhsArgs xs ns
223 rhsArgs (CA : xs) ns = pconst (PResolveTC fc) : rhsArgs xs ns
220 rhsArgs [] _ = []
224 rhsArgs [] _ = []
@@ -230,3 +234,17 @@ elabClass info syn_in doc fc constraints tn ps pDocs ds
230 | otherwise = PPi (e l s p) n ty (toExp ns e sc)
234 | otherwise = PPi (e l s p) n ty (toExp ns e sc)
231 toExp ns e (PPi p n ty sc) = PPi p n ty (toExp ns e sc)
235 toExp ns e (PPi p n ty sc) = PPi p n ty (toExp ns e sc)
232 toExp ns e sc = sc
236 toExp ns e sc = sc
238+findDets :: Name -> [Name] -> Idris [Int]
241+ return $ case lookupTyExact n (tt_ctxt i) of
242+ Just ty -> getDetPos 0 ns ty
245+ getDetPos i ns (Bind n (Pi _ _ _) sc)
246+ | n `elem` ns = i : getDetPos (i + 1) ns sc
247+ | otherwise = getDetPos (i + 1) ns sc
248+ getDetPos _ _ _ = []