@@ -67,7 +67,7 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
6767 let (t, _) = unApply (getRetTy nty')
6868 let corec = case t of
6969 P _ rcty _ -> case lookupCtxt Nothing rcty (idris_datatypes i) of
70− [TI _ True] -> True
70+ [TI _ True _] -> True
7171 _ -> False
7272 _ -> False
7373 let opts' = if corec then (Coinductive : opts) else opts
@@ -141,7 +141,10 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
141141 cons <- mapM (elabCon info syn n codata) dcons
142142 ttag <- getName
143143 i <- get
144− put (i { idris_datatypes = addDef n (TI (map fst cons) codata)
144+ let as = map (const Nothing) (getArgTys cty)
145+ let params = findParams (zip as (repeat True)) (map snd cons)
146+ logLvl 2 $ "Parameters : " ++ show params
147+ put (i { idris_datatypes = addDef n (TI (map fst cons) codata params)
145148 (idris_datatypes i) })
146149 addIBC (IBCDef n)
147150 addIBC (IBCData n)
@@ -150,6 +153,29 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
150153 collapseCons n cons
151154 updateContext (addDatatype (Data n ttag cty cons))
152155 mapM_ (checkPositive n) cons
156+ where findParams :: [(Maybe Name, Bool)] -> [Type] -> [Int]
157+ findParams ps [] = mapMaybe (\ ((x, y), n) ->
158+ if y then Just n else Nothing)
159+ (zip ps [0..])
160+ findParams ps (t : ts) = findParams (updateParams ps t) ts
161+
162+ updateParams ps (Bind n (Pi t) sc)
163+ = updateParams ps (instantiate (P Bound n t) sc)
164+ updateParams ps tm@(App f a)
165+ | (P _ fn _, args) <- unApply tm
166+ = if fn == n
167+ then updateParamsA ps args
168+ else updateParams (updateParams ps f) a
169+ | otherwise = updateParams (updateParams ps f) a
170+ updateParams ps _ = ps
171+
172+ updateParamsA ((Nothing, b) : ns) (P _ n' _ : args)
173+ = (Just n', b) : updateParamsA ns args
174+ updateParamsA ((Just p, b) : ns) (P _ n' _ : args)
175+ = (Just n', b && p == n') : updateParamsA ns args
176+ updateParamsA ((mn, _) : ns) (_ : args)
177+ = (mn, False) : updateParamsA ns args
178+ updateParamsA ps args = ps
153179
154180elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
155181 PTerm -> String -> Name -> PTerm -> Idris ()
@@ -911,6 +937,7 @@ elabInstance info syn fc cs n ps t expn ds
911937 (n, ci) <- case lookupCtxtName (namespace info) n (idris_classes i) of
912938 [c] -> return c
913939 _ -> fail $ show fc ++ ":" ++ show n ++ " is not a type class"
940+ let constraint = PApp fc (PRef fc n) (map pexp ps)
914941 let iname = case expn of
915942 Nothing -> UN ('@':show n ++ "$" ++ show ps)
916943 Just nm -> nm
@@ -957,6 +984,10 @@ elabInstance info syn fc cs n ps t expn ds
957984 iLOG (show idecls)
958985 mapM (elabDecl EAll info) idecls
959986 addIBC (IBCInstance intInst n iname)
987+-- -- for each constraint, build a top level function to chase it
988+-- logLvl 5 $ "Building functions"
989+-- fns <- mapM (cfun (instanceName ci) constraint syn idecls) cs
990+-- mapM_ (elabDecl EAll info) (concat fns)
960991 where
961992 intInst = case ps of
962993 [PConstant IType] -> True
@@ -1048,6 +1079,31 @@ elabInstance info syn fc cs n ps t expn ds
10481079 = decorate ns iname m == decorate ns iname m'
10491080 clauseFor m iname ns _ = False
10501081
1082+{- This won't work yet. Can it ever, in this form?
1083+
1084+ cfun cn c syn all con
1085+ = do let cfn = UN ('@':'@':show cn ++ "#" ++ show con)
1086+ let mnames = take (length all) $ map (\x -> MN x "meth") [0..]
1087+ let capp = PApp fc (PRef fc cn) (map (pexp . PRef fc) mnames)
1088+ let lhs = PApp fc (PRef fc cfn) [pconst capp]
1089+ let rhs = PResolveTC (FC "HACK" 0)
1090+ let ty = PPi constraint (MN 0 "pc") c con
1091+ iLOG (showImp True ty)
1092+ iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
1093+ i <- get
1094+ let conn = case con of
1095+ PRef _ n -> n
1096+ PApp _ (PRef _ n) _ -> n
1097+ let conn' = case lookupCtxtName Nothing conn (idris_classes i) of
1098+ [(n, _)] -> n
1099+ _ -> conn
1100+ addInstance False conn' cfn
1101+ addIBC (IBCInstance False conn' cfn)
1102+ iputStrLn ("Added " ++ show (conn, cfn, ty) ++ "\n" ++ show (lhs, rhs))
1103+ return [PTy "" syn fc [] cfn ty,
1104+ PClauses fc [Inlinable,TCGen] cfn [PClause fc cfn lhs [] rhs []]]
1105+-}
1106+
10511107decorateid decorate (PTy doc s f o n t) = PTy doc s f o (decorate n) t
10521108decorateid decorate (PClauses f o n cs)
10531109 = PClauses f o (decorate n) (map dc cs)