Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation and example about IO operations #462

Open
blaiseli opened this issue Nov 8, 2018 · 3 comments
Open

Add documentation and example about IO operations #462

blaiseli opened this issue Nov 8, 2018 · 3 comments

Comments

@blaiseli
Copy link

blaiseli commented Nov 8, 2018

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.

@kevinsimper
Copy link
Contributor

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!

@blaiseli
Copy link
Author

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.

@kevinsimper
Copy link
Contributor

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants