I have a task to do in ocaml and can’t find any help information so ask here 😉 How to define function which give us something other in each call without using global variables ? I would like to do fun next() which return next odd numbers or next values of factorial.
Like this
# next();;
- : int = 1
# next();;
- : int = 3
# next();;
- : int = 5
# next();;
- : int = 7
Do you have any tips for me ?
Thanks in advance
Greg
You can also encapsulate this in a “counter factory”: