Add documentation and example about IO operations
I'm surprised how hard it is for me to understand how to write a simple program that reads from stdin or from a file and processes the data line by line.
Just after the basic syntax rules and a hello world program, to start doing some real work, I need to interact with the outside world. However, I was unable to find anything on this subject in the documentation, and I struggle understanding how to do it looking at the various modules listed in the API Where should I look? Stream, Bytes, Pervasives, Unix? Should I learn OCaml and Javascript before attempting to do some real work with ReasonML?
A documentation chapter about IO would be welcome.
Hi @blaiseli
Great question and hope you found a answer since it is some time ago, but I will add my answer still :)
It is very much up to what backend you choose, if you choose to run it with JavaScript you would have to look into how Node.js reads from STDIN, something like this:
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log(line);
})
And somebody did create the bindings for the readline native node.js package. https://redex.github.io/package/bs-readline
You can also look into how to create it with OCaml, which you can find more about here, although reasonml mostly focuses on javascript as you have seen in the docs, the bucklescript documentation has ocaml syntax you can switch to: https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora027.html
Hope that helps or else please write again here!
Hi @kevinsimper
Thanks for your answer. Actually, I'm not planning to use the JavaScript backend. I was interested by ReasonML because it looked like a promising language to have access the power of OCaml with an easier syntax. I found some solutions and posted some of them here: https://stackoverflow.com/a/53223872/1878788.
However, I realized that maybe I should rather try to learn OCaml directly, since ReasonML seems mainly directed towards web programmers.
@blaiseli Yeah, learning ocaml directly would give you a better learning path, if the target is ocaml and not bucklescript. There is things that tries to make it easy to use reasonml and package land like https://github.com/esy/esy but it still requires you to know about compilation and such :)