@@ -472,14 +472,15 @@ instance Binary (a -> b) where
472data Accessibility = Public | Frozen | Hidden
472data Accessibility = Public | Frozen | Hidden
473 deriving (Show, Eq)
473 deriving (Show, Eq)
475+data Totality = Total [Int] -- well-founded arguments
475−data Totality = Total | Partial PReason
476+ | Partial PReason
476 deriving Eq
477 deriving Eq
478−data PReason = Other [Name] | Itself | NotCovering | NotPositive
479+data PReason = Other [Name] | Itself | NotCovering | NotPositive | UseUndef Name
479 deriving (Show, Eq)
480 deriving (Show, Eq)
481instance Show Totality where
482instance Show Totality where
482− show Total = "Total"
483+ show (Total args)= "Total, " ++ show args ++ " decreasing arguments"
483 show (Partial Itself) = "not total as it is not well founded"
484 show (Partial Itself) = "not total as it is not well founded"
484 show (Partial NotCovering) = "not total as there are missing cases"
485 show (Partial NotCovering) = "not total as there are missing cases"
485 show (Partial NotPositive) = "not strictly positive"
486 show (Partial NotPositive) = "not strictly positive"
@@ -511,7 +512,7 @@ veval ctxt env t = evalState (eval ctxt emptyContext env t []) ()
511addToCtxt :: Name -> Term -> Type -> Context -> Context
512addToCtxt :: Name -> Term -> Type -> Context -> Context
512addToCtxt n tm ty uctxt
513addToCtxt n tm ty uctxt
513 = let ctxt = definitions uctxt
514 = let ctxt = definitions uctxt
514− ctxt' = addDef n (Function ty tm, Public, Total) ctxt in
515+ ctxt' = addDef n (Function ty tm, Public, Total []) ctxt in
515 uctxt { definitions = ctxt' }
516 uctxt { definitions = ctxt' }
517setAccess :: Name -> Accessibility -> Context -> Context
518setAccess :: Name -> Accessibility -> Context -> Context
@@ -528,13 +529,13 @@ setTotal n t uctxt
529addCtxtDef :: Name -> Def -> Context -> Context
530addCtxtDef :: Name -> Def -> Context -> Context
530addCtxtDef n d c = let ctxt = definitions c
531addCtxtDef n d c = let ctxt = definitions c
531− ctxt' = addDef n (d, Public, Total) ctxt in
532+ ctxt' = addDef n (d, Public, Total []) ctxt in
532 c { definitions = ctxt' }
533 c { definitions = ctxt' }
534addTyDecl :: Name -> Type -> Context -> Context
535addTyDecl :: Name -> Type -> Context -> Context
535addTyDecl n ty uctxt
536addTyDecl n ty uctxt
536 = let ctxt = definitions uctxt
537 = let ctxt = definitions uctxt
537− ctxt' = addDef n (TyDecl Ref ty, Public, Total) ctxt in
538+ ctxt' = addDef n (TyDecl Ref ty, Public, Total []) ctxt in
538 uctxt { definitions = ctxt' }
539 uctxt { definitions = ctxt' }
540addDatatype :: Datatype Name -> Context -> Context
541addDatatype :: Datatype Name -> Context -> Context
@@ -542,14 +543,14 @@ addDatatype (Data n tag ty cons) uctxt
542 = let ctxt = definitions uctxt
543 = let ctxt = definitions uctxt
543 ty' = normalise uctxt [] ty
544 ty' = normalise uctxt [] ty
544 ctxt' = addCons 0 cons (addDef n
545 ctxt' = addCons 0 cons (addDef n
545− (TyDecl (TCon tag (arity ty')) ty, Public, Total) ctxt) in
546+ (TyDecl (TCon tag (arity ty')) ty, Public, Total []) ctxt) in
546 uctxt { definitions = ctxt' }
547 uctxt { definitions = ctxt' }
548 addCons tag [] ctxt = ctxt
549 addCons tag [] ctxt = ctxt
549 addCons tag ((n, ty) : cons) ctxt
550 addCons tag ((n, ty) : cons) ctxt
550 = let ty' = normalise uctxt [] ty in
551 = let ty' = normalise uctxt [] ty in
551 addCons (tag+1) cons (addDef n
552 addCons (tag+1) cons (addDef n
552− (TyDecl (DCon tag (arity ty')) ty, Public, Total) ctxt)
553+ (TyDecl (DCon tag (arity ty')) ty, Public, Total []) ctxt)
554addCasedef :: Name -> Bool -> Bool -> Bool -> [(Term, Term)] -> [(Term, Term)] ->
555addCasedef :: Name -> Bool -> Bool -> Bool -> [(Term, Term)] -> [(Term, Term)] ->
555 Type -> Context -> Context
556 Type -> Context -> Context
@@ -561,7 +562,7 @@ addCasedef n alwaysInline tcase covering ps psrt ty uctxt
561 (CaseDef args sc _, CaseDef args' sc' _) ->
562 (CaseDef args sc _, CaseDef args' sc' _) ->
562 let inl = alwaysInline in
563 let inl = alwaysInline in
563 addDef n (CaseOp inl ty ps args sc args' sc',
564 addDef n (CaseOp inl ty ps args sc args' sc',
564− Public, Total) ctxt in
565+ Public, Total []) ctxt in
565 uctxt { definitions = ctxt' }
566 uctxt { definitions = ctxt' }
566 where simpl [] = []
567 where simpl [] = []
567 simpl ((l,r) : xs) = (l, simplify uctxt [] r) : simpl xs
568 simpl ((l,r) : xs) = (l, simplify uctxt [] r) : simpl xs
@@ -569,7 +570,7 @@ addCasedef n alwaysInline tcase covering ps psrt ty uctxt
569addOperator :: Name -> Type -> Int -> ([Value] -> Maybe Value) -> Context -> Context
570addOperator :: Name -> Type -> Int -> ([Value] -> Maybe Value) -> Context -> Context
570addOperator n ty a op uctxt
571addOperator n ty a op uctxt
571 = let ctxt = definitions uctxt
572 = let ctxt = definitions uctxt
572− ctxt' = addDef n (Operator ty a op, Public, Total) ctxt in
573+ ctxt' = addDef n (Operator ty a op, Public, Total []) ctxt in
573 uctxt { definitions = ctxt' }
574 uctxt { definitions = ctxt' }
575tfst (a, _, _) = a
576tfst (a, _, _) = a