Hello there.
I’m a long time fan of OCaml and especially of TryOCaml.
I think that for teaching OCaml and teaching computer science with OCaml, having a web-based in-browser OCaml interpreter like TryOCaml is already a great tool, easing the first contact with the language and its REPL ocaml
in a terminal.
But using a REPL has the limitations that we all know, it’s so “static”: you type, hit enter, and see the result, one statement at a time…
There also exists web-based in-browser OCaml editors and interpreters that go one step further, I’m thinking of “Learn OCaml”, <Sketch.sh> or others.
There also exists two “kernels” to use OCaml in IPython or Jupyter notebook, and one is even available to try online, with OCaml code executed in javascript: IOCaml-JS by @andrewray on GitHub (have a look if you don’t know that, it’s quite powerfull!), and also ocaml-jupyter by akabe, which is a more complete kernel, but needs a server under the hood, able to run ocaml
.
But it’s still not interactive enough, I have to write the code, hit run, see the result, and iteratively do that over and over as the code progresses. I want more!
So after digging, I just discovered that Reason documentation has this page https://reasonml.github.io/en/try which lets you write OCaml (or Reason) code, and automatically “live” converts it OCaml <-> Reason (on the left), to JavaScript (with BuckleScript), and more importantly it executes your code continuously!!
That’s it, a live coding environment for OCaml (and Reason). It was written and improved in 2017.
But it’s overly complicated for the simpler goal of teaching OCaml, and half the screen space is used by Reason code. It also does not show the - val : ...
and type inference that ocaml
REPL shows when executing code, both of which are very useful when teaching (with) OCaml.
I also found this playground for Revery by outrunlabs, and Reason React playground by astrada on GitHub.
But apparently nothing exists for basic OCaml !! It’s quite ironic, as all these recents Reason and Revery and others tools are standing on the shoulder of the giant that is OCaml, but no such tools have been proposed for the “base” language.
I think a lot of teachers that teach OCaml at University could benefit to have this kind of live coding or live programming environment, but in a simplified version: just OCaml code on the left, and both result of OCaml toplevel (using js_of_ocaml version of ocaml topleve) and result of execution (just the stdout) on the right (maybe two panels, like in the Reason “try” page).
What do you guys think?
I’ve looked for this in depth on the Internet and here, and couldn’t find anything, not even a mention of “a live coding environment for OCaml”, nothing. See for instance on awesome-ocaml on GitHub: TryOCaml is mentioned, but nothing else in the same spirit.
If indeed you can confirm that nothing exists (yet), then I would like to write this myself, but would need some help… when seeing the code for the Reason playground, I don’t understand much of it.
This is inspired by the great « Bret Victor - Inventing on Principle » video (on YouTube). I’m quite amazed to see how few of these live coding environments exists, even for major languages such as Python. For VSCode, apparently the only serious one is the extension fraser.live-coder
.
Thanks for your insights.