[m-users.] Ambiguous tail recursion?

Julian Fondren jfondren at minimaltype.com
Wed Jul 17 11:18:40 AEST 2019


Hello, and thanks for your previous answers.

Consider this module:

   :- module tailornot.
   :- interface.
   :- import_module io.
   :- pred main(io::di, io::uo) is det.
   :- implementation.
   :- import_module list, bool, int.

   main(!IO) :-
       X = (test([1, 2, 3]) -> yes; no),
       io.print(X, !IO), io.nl(!IO).

   :- pred test(list(int)::in) is semidet.
   test([]).
   test([X | Xs]) :-
       X < 5,
       test(Xs).

Is it defined that test/1 is tail recursive?

It seems to be just as valid for it to walk to the end of the list,
hit the [], and then walk backwards to test 3 < 5, 2 < 5, 1 < 5.


More information about the users mailing list