dataprop TALLY (int, int) =
| TALLYbas (0, 0)
| {n:nat} {r:int} TALLYind (n+1, r+n+1) of TALLY (n, r)
fun tally1 {n:nat} .<n>.
(x: int n):<> [r:int] (TALLY (n, r) | int r) =
if x > 0 then let
val (pf | res) = tally1 (x-1)
in
(TALLYind pf | res + x)
end else begin
(TALLYbas () | 0)
end
fun tally2 {n:nat} .<n>.
(x: int n):<> [r:int] (TALLY (n, r) | int r) = let
fun loop {n:nat} {r0:int} .<n>. (x: int n, res: int r0)
:<> [r:int] (TALLY (n, r) | int (r+r0)) =
if x > 0 then
let val (pf | res) = loop (x-1, res + x)
in
(TALLYind pf | res)
end else begin
(TALLYbas () | res)
end in
loop (x, 0)
end