solution p04.ml without tail call