Thanks to your suggestions, I then tried
imperative way to produce the required result,
# let newsymb = let c = ref 0 in
function s -> c := !c +1; s^(string_of_int !c) ;;
# let _ = for i =0 to 3 do
print_endline (newsymb "Var"); done ;;
Besides I was confused with different types of below:
# let newsymb1 = let c = ref 0 in
function s -> s^(string_of_int !c); c := !c +1 ;;
Characters 47-67:
Warning S: this expression should have type unit.
function s -> s^(string_of_int !c); c := !c +1 ;;
^^^^^^^^^^^^^^^^^^^^
val newsymb1 : string -> unit = <fun>
# let newsymb2 = let c = ref 0 in
function s -> c := !c +1; s^(string_of_int !c) ;;
val newsymb2 : string -> string = <fun>
Why the order of statement c := !c +1 changed,
the types of two function changed ?
--- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Fabrice Marchant
<fabrice.marchant
...> wrote:
>
> Hi Lorenzo,
>
> I do not think there is a side effect problem but rather a
conception issue.
>
> Such an iterating function - that make remember the "fold"s of the
library - can be useful if the "iterated" function can easily continue
its work leaning on the result of the nested call.
>
> If you absolutely want the functional "iterate" on "new-symb"
behaves like this :
>
>
> It would be so simple to stringify the number argument (3) and to
concatenate to "Var"...
>
> Regards,
>
> Fabrice
>