Registry Mirror
Skip to content

Add documentation and example about IO operations #462

Open

Description

@blaiseli

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.

Activity

  1. kevinsimper commented on Jan 14, 2019

    @kevinsimper
    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!

  2. blaiseli commented on Jan 17, 2019

    @blaiseli
    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.

  3. kevinsimper commented on Jan 17, 2019

    @kevinsimper
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions