a-conjecture-of-mine

An exercise on polyglossy: the same problem solved on multiple languages

main.m (399B)

 1 :- module main.
 2 :- interface.
 3 :- import_module io.
 4 :- import_module int.
 5 :- pred main(io::di, io::uo) is det.
 6 :- implementation.
 7 
 8 :- func sum_digits_acc(int, int) = int.
 9 sum_digits_acc(N, Acc) = (if N = 0 then Acc else sum_digits_acc(N div 10, Acc + (N mod 10))).
10 
11 :- func sum_digits(int) = int.
12 sum_digits(N) = sum_digits_acc(N, 0).
13 
14 main(!IO) :-
15   io.write_int(sum_digits(55), !IO),
16   io.nl(!IO).