[discuss] what would be the syntax for oo with the rescript ocaml syntax?

What would be the syntax for oo with the rescript ocaml syntax ?

type position = {
  x: int,
  y: int,
}

class Foo = {
  let name: string
  let pos: position

  new(name: string, pos: position) = {
    name: name,
    pos: p,
  }

  let getName() = {
    Js.log("My name is: " ++ name ++ ".")
  }

  let getPos() = pos
}

Also I saw that the rescript syntax has been removed from melange, what is its last version before it got removed ?

This is a question for the ReScript forum: https://forum.rescript-lang.org/

1 Like

This is a question for the ocaml forum if we make a rescript syntax for ocaml.

This was something that was far beyond my skills in the past, but I’m trying to figure out if I could do it with the help of the new chat-bots that appeared.

There are a lot of parts of the ocaml system that I was not able to understand in the past, and the explanations from these chat-bots make me able to understand it.

With the help of these chat-bots I have been able to understand gadts, the multi-threading models of ocaml, and how to use op-codes.

If I understood correctly the earlier versions of melange was still providing the rescript syntax, before to switch to the reason one.

I was not able to understand how the ocaml-alternative syntax was build, but with the help of these chat-bots, maybe it could become possible.

I’m sorry if I’m confused and answering with something completely irrelevant, but isn’t https://reasonml.github.io/ still relevant? It’s maintained and used by companies, and it has some syntax for objects/classes

class stack_of_ints = {
  as self;
  val mutable the_list: list(int) = []; /* instance variable */
  pub push = x =>
    /* push method */
    the_list = [x, ...the_list];
  pub pop =
    {
      let result = List.hd(the_list);
      the_list = List.tl(the_list);
      result;
    } /* pop method */;
  pub peek =
    List.hd(the_list) /* peek method */;
  pub size =
    List.length(the_list) /* size method */;
};

Yes, it also looks nice, I bet there is also imperative, and functional objects ?
We need a tutorial for that, would you accept that I copy-past your example to start one ?

my example was actually an automatic translation of the ocaml code found in Objects · OCaml Documentation , so please feel free to reuse it as you see fit

the reason syntax should support all the ocaml features, plus jsx. But it doesn’t have some of the niceties of the rescript syntax.