@@ -58,14 +58,24 @@ elabType info syn fc opts n ty' = {- let ty' = piBind (params info) ty_in
58 addStatics n cty ty'
58 addStatics n cty ty'
59 logLvl 2 $ "---> " ++ show cty
59 logLvl 2 $ "---> " ++ show cty
60 let nty = cty -- normalise ctxt [] cty
60 let nty = cty -- normalise ctxt [] cty
61+ -- if the return type is something coinductive, freeze the definition
62+ let nty' = normalise ctxt [] nty
61 ds <- checkDef fc [(n, nty)]
63 ds <- checkDef fc [(n, nty)]
62 addIBC (IBCDef n)
64 addIBC (IBCDef n)
63 addDeferred ds
65 addDeferred ds
64 setFlags n opts
66 setFlags n opts
65 addIBC (IBCFlags n opts)
67 addIBC (IBCFlags n opts)
68+ let (t, _) = unApply (getRetTy nty')
70+ P _ rcty _ -> case lookupCtxt Nothing rcty (idris_datatypes i) of
71+ [TI _ True] -> do setAccessibility n Frozen
72+ addIBC (IBCAccess n Frozen)
73+ iputStrLn $ "Co " ++ show n
67−elabData :: ElabInfo -> SyntaxInfo -> FC -> PData -> Idris ()
77+elabData :: ElabInfo -> SyntaxInfo -> FC -> Bool -> PData -> Idris ()
68−elabData info syn fc (PDatadecl n t_in dcons)
78+elabData info syn fc codata (PDatadecl n t_in dcons)
69 = do iLOG (show fc)
79 = do iLOG (show fc)
70 checkUndefined fc n
80 checkUndefined fc n
71 ctxt <- getContext
81 ctxt <- getContext
@@ -80,11 +90,11 @@ elabData info syn fc (PDatadecl n t_in dcons)
80 (cty, _) <- recheckC fc [] t'
90 (cty, _) <- recheckC fc [] t'
81 logLvl 2 $ "---> " ++ show cty
91 logLvl 2 $ "---> " ++ show cty
82 updateContext (addTyDecl n cty) -- temporary, to check cons
92 updateContext (addTyDecl n cty) -- temporary, to check cons
83− cons <- mapM (elabCon info syn n) dcons
93+ cons <- mapM (elabCon info syn n codata) dcons
84 ttag <- getName
94 ttag <- getName
86− put (i { idris_datatypes = addDef n (TI (map fst cons))
96+ put (i { idris_datatypes = addDef n (TI (map fst cons) codata)
87− (idris_datatypes i) })
97+ (idris_datatypes i) })
88 addIBC (IBCDef n)
98 addIBC (IBCDef n)
89 addIBC (IBCData n)
99 addIBC (IBCData n)
90 collapseCons n cons
100 collapseCons n cons
@@ -94,7 +104,7 @@ elabData info syn fc (PDatadecl n t_in dcons)
94elabRecord :: ElabInfo -> SyntaxInfo -> FC -> Name ->
104elabRecord :: ElabInfo -> SyntaxInfo -> FC -> Name ->
95 PTerm -> Name -> PTerm -> Idris ()
105 PTerm -> Name -> PTerm -> Idris ()
96elabRecord info syn fc tyn ty cn cty
106elabRecord info syn fc tyn ty cn cty
97− = do elabData info syn fc (PDatadecl tyn ty [(cn, cty, fc)])
107+ = do elabData info syn fc False (PDatadecl tyn ty [(cn, cty, fc)])
98 cty' <- implicit syn cn cty
108 cty' <- implicit syn cn cty
100 cty <- case lookupTy Nothing cn (tt_ctxt i) of
110 cty <- case lookupTy Nothing cn (tt_ctxt i) of
@@ -200,12 +210,12 @@ elabRecord info syn fc tyn ty cn cty
200 (map pexp rhsArgs)) []
210 (map pexp rhsArgs)) []
201 return (pn, pfnTy, PClauses fc [] setname [pclause])
211 return (pn, pfnTy, PClauses fc [] setname [pclause])
203−elabCon :: ElabInfo -> SyntaxInfo -> Name -> (Name, PTerm, FC) -> Idris (Name, Type)
213+elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool -> (Name, PTerm, FC) -> Idris (Name, Type)
204−elabCon info syn tn (n, t_in, fc)
214+elabCon info syn tn codata (n, t_in, fc)
205 = do checkUndefined fc n
215 = do checkUndefined fc n
206 ctxt <- getContext
216 ctxt <- getContext
208− t_in <- implicit syn n t_in
218+ t_in <- implicit syn n (if codata then mkLazy t_in else t_in)
209 let t = addImpl i t_in
219 let t = addImpl i t_in
210 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
220 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
211 ((t', defer, is), log) <- tclift $ elaborate ctxt n (Set (UVal 0)) []
221 ((t', defer, is), log) <- tclift $ elaborate ctxt n (Set (UVal 0)) []
@@ -229,6 +239,9 @@ elabCon info syn tn (n, t_in, fc)
229 else return ()
239 else return ()
230 tyIs t = tclift $ tfail (At fc (Msg (show t ++ " is not " ++ show tn)))
240 tyIs t = tclift $ tfail (At fc (Msg (show t ++ " is not " ++ show tn)))
242+ mkLazy (PPi pl n ty sc) = PPi (pl { plazy = True }) n ty (mkLazy sc)
232elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
245elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
233elabClauses info fc opts n_in cs = let n = liftname info n_in in
246elabClauses info fc opts n_in cs = let n = liftname info n_in in
234 do ctxt <- getContext
247 do ctxt <- getContext
@@ -605,7 +618,7 @@ elabClass info syn fc constraints tn ps ds
605 let cons = [(cn, cty, fc)]
618 let cons = [(cn, cty, fc)]
606 let ddecl = PDatadecl tn tty cons
619 let ddecl = PDatadecl tn tty cons
607 logLvl 5 $ "Class data " ++ showDImp True ddecl
620 logLvl 5 $ "Class data " ++ showDImp True ddecl
608− elabData info (syn { no_imp = no_imp syn ++ mnames }) fc ddecl
621+ elabData info (syn { no_imp = no_imp syn ++ mnames }) fc False ddecl
609 -- for each constraint, build a top level function to chase it
622 -- for each constraint, build a top level function to chase it
610 logLvl 5 $ "Building functions"
623 logLvl 5 $ "Building functions"
611 let usyn = syn { using = ps ++ using syn }
624 let usyn = syn { using = ps ++ using syn }
@@ -899,8 +912,8 @@ elabDecl' info (PFix _ _ _) = return () -- nothing to elaborate
899elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
912elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
900elabDecl' info (PTy s f o n ty) = do iLOG $ "Elaborating type decl " ++ show n ++ show o
913elabDecl' info (PTy s f o n ty) = do iLOG $ "Elaborating type decl " ++ show n ++ show o
901 elabType info s f o n ty
914 elabType info s f o n ty
902−elabDecl' info (PData s f d) = do iLOG $ "Elaborating " ++ show (d_name d)
915+elabDecl' info (PData s f co d) = do iLOG $ "Elaborating " ++ show (d_name d)
903− elabData info s f d
916+ elabData info s f co d
904elabDecl' info d@(PClauses f o n ps) = do iLOG $ "Elaborating clause " ++ show n
917elabDecl' info d@(PClauses f o n ps) = do iLOG $ "Elaborating clause " ++ show n
905 i <- get -- get the type options too
918 i <- get -- get the type options too
906 let o' = case lookupCtxt Nothing n (idris_flags i) of
919 let o' = case lookupCtxt Nothing n (idris_flags i) of