I have written some state machine in C++ and Java but never in a functional language like Ocaml
Problem is I don\'t know if I can just adapt code from the object languag
There is an excellent answer which demonstrates expressiveness and elegance of OCaml in representing finite state machine here:
automata in ocaml
For more serious use, you could try to look at some finite state machine library like fsm library here.