Reputation: 181
Can we print a string in Ocaml without using print_string that it imperative function (I don't know if we can say that). I want a function defined in pure Ocaml. Thanks for your help.
Upvotes: 0
Views: 804
Reputation: 80255
Pure OCaml does not have side-effects. Printing is a side-effect. If you want your program to be pure, build a string. Both Printf.sprintf
and ^
can help.
If the total amount of text you intend to build in a purely functional fashion is large, use a data structure that scales to larger contents, such as the rope.
Upvotes: 4