@@ -472,14 +472,15 @@ instance Binary (a -> b) where
472472data Accessibility = Public | Frozen | Hidden
473473 deriving (Show, Eq)
474474
475−data Totality = Total | Partial PReason
475+data Totality = Total [Int] -- well-founded arguments
476+ | Partial PReason
476477 deriving Eq
477478
478−data PReason = Other [Name] | Itself | NotCovering | NotPositive
479+data PReason = Other [Name] | Itself | NotCovering | NotPositive | UseUndef Name
479480 deriving (Show, Eq)
480481
481482instance Show Totality where
482− show Total = "Total"
483+ show (Total args)= "Total, " ++ show args ++ " decreasing arguments"
483484 show (Partial Itself) = "not total as it is not well founded"
484485 show (Partial NotCovering) = "not total as there are missing cases"
485486 show (Partial NotPositive) = "not strictly positive"
@@ -511,7 +512,7 @@ veval ctxt env t = evalState (eval ctxt emptyContext env t []) ()
511512addToCtxt :: Name -> Term -> Type -> Context -> Context
512513addToCtxt n tm ty uctxt
513514 = 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
515516 uctxt { definitions = ctxt' }
516517
517518setAccess :: Name -> Accessibility -> Context -> Context
@@ -528,13 +529,13 @@ setTotal n t uctxt
528529
529530addCtxtDef :: Name -> Def -> Context -> Context
530531addCtxtDef 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
532533 c { definitions = ctxt' }
533534
534535addTyDecl :: Name -> Type -> Context -> Context
535536addTyDecl n ty uctxt
536537 = 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
538539 uctxt { definitions = ctxt' }
539540
540541addDatatype :: Datatype Name -> Context -> Context
@@ -542,14 +543,14 @@ addDatatype (Data n tag ty cons) uctxt
542543 = let ctxt = definitions uctxt
543544 ty' = normalise uctxt [] ty
544545 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
546547 uctxt { definitions = ctxt' }
547548 where
548549 addCons tag [] ctxt = ctxt
549550 addCons tag ((n, ty) : cons) ctxt
550551 = let ty' = normalise uctxt [] ty in
551552 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)
553554
554555addCasedef :: Name -> Bool -> Bool -> Bool -> [(Term, Term)] -> [(Term, Term)] ->
555556 Type -> Context -> Context
@@ -561,7 +562,7 @@ addCasedef n alwaysInline tcase covering ps psrt ty uctxt
561562 (CaseDef args sc _, CaseDef args' sc' _) ->
562563 let inl = alwaysInline in
563564 addDef n (CaseOp inl ty ps args sc args' sc',
564− Public, Total) ctxt in
565+ Public, Total []) ctxt in
565566 uctxt { definitions = ctxt' }
566567 where simpl [] = []
567568 simpl ((l,r) : xs) = (l, simplify uctxt [] r) : simpl xs
@@ -569,7 +570,7 @@ addCasedef n alwaysInline tcase covering ps psrt ty uctxt
569570addOperator :: Name -> Type -> Int -> ([Value] -> Maybe Value) -> Context -> Context
570571addOperator n ty a op uctxt
571572 = 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
573574 uctxt { definitions = ctxt' }
574575
575576tfst (a, _, _) = a