I have a Gallina (Coq) program that I am extracting to OCaml. The program is a (symbolic) interpreter for a small programming language, and I defined functions to stringify the states so I can print them. Unfortunately these functions are the real bottleneck in the code: While it can take a few millis to produce a final state, it can take hours to convert them to string - states are very big inductive data structures. I suspect that the problem is due to the many string concatenation operations done recursively by code like e.g.:
Fixpoint stringify (x : state) : string :=
match state with
| a => "a"
| b x y => b ++ (stringify x) ++ (stringify y)
...
Can you suggest a more efficient way to extract string code to OCaml, or to implement the Gallina functions?
P.S. Sorry for the sketchy description of the problem. I preferred to stay abstract rather than to provide details that might be not really relevant (I have no clear idea of which part of the stringification code is slow). If you ask me I will provide more details.