@@ -351,56 +351,6 @@ checkPositive mut_ns (cn, ty')
351351 noRec arg = all (\x -> x `notElem` mut_ns) (allTTNames arg)
352352
353353
354−calcProd :: IState -> FC -> Name -> [([Name], Term, Term)] -> Idris Totality
355−calcProd i fc topn pats
356− = cp topn pats []
357− where
358− -- every application of n must be in an argument of a coinductive
359− -- constructor, in every function reachable from here in the
360− -- call graph.
361− cp n pats done = do patsprod <- mapM (prodRec n done) pats
362− if (and patsprod)
363− then return Productive
364− else return (Partial NotProductive)
365−
366− prodRec :: Name -> [Name] -> ([Name], Term, Term) -> Idris Bool
367− prodRec n done _ | n `elem` done = return True
368− prodRec n done (_, _, tm) = prod n done False (delazy' True tm)
369−
370− prod :: Name -> [Name] -> Bool -> Term -> Idris Bool
371− prod n done ok ap@(App _ _ _)
372− | (P nt f _, args) <- unApply ap
373− = do recOK <- checkProdRec (n:done) f
374− let ctxt = tt_ctxt i
375− let [ty] = lookupTy f ctxt -- must exist!
376− let co = cotype nt f ty in
377− if (not recOK) then return False else
378− if f == topn
379− then do argsprod <- mapM (prod n done co) args
380− return (and (ok : argsprod) )
381− else do argsprod <- mapM (prod n done co) args
382− return (and argsprod)
383− prod n done ok (App _ f a) = liftM2 (&&) (prod n done False f)
384− (prod n done False a)
385− prod n done ok (Bind _ (Let t v) sc)
386− = liftM2 (&&) (prod n done False v) (prod n done False v)
387− prod n done ok (Bind _ b sc) = prod n done ok sc
388− prod n done ok t = return True
389−
390− checkProdRec :: [Name] -> Name -> Idris Bool
391− checkProdRec done f
392− = case lookupCtxt f (idris_patdefs i) of
393− [(def, _)] -> do ok <- mapM (prodRec f done) def
394− return (and ok)
395− _ -> return True -- defined elsewhere, can't call topn
396−
397− cotype (DCon _ _ _) n ty
398− | (P _ t _, _) <- unApply (getRetTy ty)
399− = case lookupCtxt t (idris_datatypes i) of
400− [TI _ True _ _ _] -> True
401− _ -> False
402− cotype nt n ty = False
403−
404354-- | Calculate the totality of a function from its patterns.
405355-- Either follow the size change graph (if inductive) or check for
406356-- productivity (if coinductive)