@@ -58,14 +58,24 @@ elabType info syn fc opts n ty' = {- let ty' = piBind (params info) ty_in
5858 addStatics n cty ty'
5959 logLvl 2 $ "---> " ++ show cty
6060 let nty = cty -- normalise ctxt [] cty
61+ -- if the return type is something coinductive, freeze the definition
62+ let nty' = normalise ctxt [] nty
6163 ds <- checkDef fc [(n, nty)]
6264 addIBC (IBCDef n)
6365 addDeferred ds
6466 setFlags n opts
6567 addIBC (IBCFlags n opts)
68+ let (t, _) = unApply (getRetTy nty')
69+ case t of
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
74+ _ -> return ()
75+ _ -> return ()
6676
67−elabData :: ElabInfo -> SyntaxInfo -> FC -> PData -> Idris ()
68−elabData info syn fc (PDatadecl n t_in dcons)
77+elabData :: ElabInfo -> SyntaxInfo -> FC -> Bool -> PData -> Idris ()
78+elabData info syn fc codata (PDatadecl n t_in dcons)
6979 = do iLOG (show fc)
7080 checkUndefined fc n
7181 ctxt <- getContext
@@ -80,11 +90,11 @@ elabData info syn fc (PDatadecl n t_in dcons)
8090 (cty, _) <- recheckC fc [] t'
8191 logLvl 2 $ "---> " ++ show cty
8292 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
8494 ttag <- getName
8595 i <- get
86− put (i { idris_datatypes = addDef n (TI (map fst cons))
87− (idris_datatypes i) })
96+ put (i { idris_datatypes = addDef n (TI (map fst cons) codata)
97+ (idris_datatypes i) })
8898 addIBC (IBCDef n)
8999 addIBC (IBCData n)
90100 collapseCons n cons
@@ -94,7 +104,7 @@ elabData info syn fc (PDatadecl n t_in dcons)
94104elabRecord :: ElabInfo -> SyntaxInfo -> FC -> Name ->
95105 PTerm -> Name -> PTerm -> Idris ()
96106elabRecord 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)])
98108 cty' <- implicit syn cn cty
99109 i <- get
100110 cty <- case lookupTy Nothing cn (tt_ctxt i) of
@@ -200,12 +210,12 @@ elabRecord info syn fc tyn ty cn cty
200210 (map pexp rhsArgs)) []
201211 return (pn, pfnTy, PClauses fc [] setname [pclause])
202212
203−elabCon :: ElabInfo -> SyntaxInfo -> Name -> (Name, PTerm, FC) -> Idris (Name, Type)
204−elabCon info syn tn (n, t_in, fc)
213+elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool -> (Name, PTerm, FC) -> Idris (Name, Type)
214+elabCon info syn tn codata (n, t_in, fc)
205215 = do checkUndefined fc n
206216 ctxt <- getContext
207217 i <- get
208− t_in <- implicit syn n t_in
218+ t_in <- implicit syn n (if codata then mkLazy t_in else t_in)
209219 let t = addImpl i t_in
210220 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
211221 ((t', defer, is), log) <- tclift $ elaborate ctxt n (Set (UVal 0)) []
@@ -229,6 +239,9 @@ elabCon info syn tn (n, t_in, fc)
229239 else return ()
230240 tyIs t = tclift $ tfail (At fc (Msg (show t ++ " is not " ++ show tn)))
231241
242+ mkLazy (PPi pl n ty sc) = PPi (pl { plazy = True }) n ty (mkLazy sc)
243+ mkLazy t = t
244+
232245elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
233246elabClauses info fc opts n_in cs = let n = liftname info n_in in
234247 do ctxt <- getContext
@@ -605,7 +618,7 @@ elabClass info syn fc constraints tn ps ds
605618 let cons = [(cn, cty, fc)]
606619 let ddecl = PDatadecl tn tty cons
607620 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
609622 -- for each constraint, build a top level function to chase it
610623 logLvl 5 $ "Building functions"
611624 let usyn = syn { using = ps ++ using syn }
@@ -899,8 +912,8 @@ elabDecl' info (PFix _ _ _) = return () -- nothing to elaborate
899912elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
900913elabDecl' info (PTy s f o n ty) = do iLOG $ "Elaborating type decl " ++ show n ++ show o
901914 elabType info s f o n ty
902−elabDecl' info (PData s f d) = do iLOG $ "Elaborating " ++ show (d_name d)
903− elabData info s f d
915+elabDecl' info (PData s f co d) = do iLOG $ "Elaborating " ++ show (d_name d)
916+ elabData info s f co d
904917elabDecl' info d@(PClauses f o n ps) = do iLOG $ "Elaborating clause " ++ show n
905918 i <- get -- get the type options too
906919 let o' = case lookupCtxt Nothing n (idris_flags i) of