Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I just want OCAML to have curly braces, please. And the variable scope thing in OCAML is extremely off putting.


Have you tried reason? Seems like a step in the direction you're looking for anyway


You can use the ReasonML syntax with the standard OCaml toolchain, it's the same language with curly braces. (Not to be confused with ReScript which spun off of it, but is now a different language that only targets the JavaScript stack.)

Do you simply dislike the OCaml syntax or is it some particular quirk?

> the variable scope thing

The what thing? Variables are just lexically scoped, are you referring to shadowing?


Convenience link here: https://reasonml.github.io/

(When you look at the blog, you'll see that the last blog update was in 2018, and you might conclude that the project is dead. But it's actually not -- their Github repo is still getting new commits!)


I believe the Reason syntax for OCaml is now maintained by the same people as Melange; which is the revived version of BuckleScript, the OCaml fork targeting JS, from which Reason and later ReScript spun off.


Heh, the family lineage here is very complicated!


IIRC every variable have an anonymous name based on their scope. So

a = 10; { a = 20; } print(a)

This would print 10. Something like that. I just remembered that the first time I encountered this, I thought "this is going to be one of those things where I will unnecessarily trip over" and closed the page.


You did mean shadowing then. But your example is deceptive, that C-like assignment syntax doesn't exist in Reason, much less in OCaml. The real Reason syntax makes the shadowing much clearer:

  let a = 10;
  {
    let a = 20;
  }
  print(a);
And even more clear in OCaml:

  let a = 10 in
  begin
    let a = 20 in
    ()
  end;
  print a
BTW you should also close the page on Rust then, which also has OCaml-like variable shadowing (and many other languages use very similar forms of shadowing, such as local variables shadowing object fields in Java/C#).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: