124 points · by juliendemangeon · 6y ago · 118 comments
Also note that despite the "O" in the name, OOP in OCaml is rare (for instance, there isn't any in the code in the article).
Which is kinda sad, because it has one of the best OO type systems in the industry, in my opinion. The decoupling of inheritance and subtyping, in particular.
- https://esy.sh/ - a package manager that offers a lockfile, aggressive build caching, and reproducible hermetic builds. So when you come back to a project a few months later, it still builds.
- https://reason-native.com/ - an umbrella for useful Reason-oriented native libraries
Runs with WebGL and OpenGL.
Especially if you're targeting native, so all your dependencies are written and documented in OCaml syntax.
I'm not sure why the author decided to use such a complicated setup using Make and Docker.
They could have just ran `opam switch create 4.09.0`, which would have created the compiler, then `opam install ...` for the dependencies.
Still, an interesting article. I wouldn't recommending using OCaml/ReasonML for gamedev since getting it to work with Windows is pretty much impossible.
I find OCaml really enjoyable once I got going, but I do think the initial setup is a major barrier to larger adoption. I think a post on howistart.org might be useful, but it'd probably be polarizing since most functions have two major ways of doing it (Jane Street vs. not, Lwt vs. Async, etc.).
For a while, I grumbled that it had spoiled me for other languages, the "fun" looking stuff that everyone talks about online. But as with all... rustic... experiences, it's only fun for the weekend. I wouldn't want to spend my entire life chopping wood for fuel, either. Even after spending 3 years fully in JavaScript land, getting very comfortable with all of the tools, it never really got "good enough". Years of effort and my dev experience was still worse than a default VS install. So I went back and have been loving life again.
Docker because, presumably, he didn't want to dink with installing it locally.
Sorry, what is not straightforward in building with `dune`?
- How do I run tests? Oh, you can't really dune runtest on executables, only libraries. So how do I run tests on executables? Make a library with the core of the functionality and wrap it, I guess. Wasn't obvious.
- Tree-like heirarchy of dune files confused me since it wasn't really explained anywhere. I wanted my source files in a `src` directory; most of the examples assume your `dune` file is just hanging out with the source in the toplevel.
- Does `dune` handle dependencies (like I would declare them in a rebar.config, mix.exs, or a package.json)? Not really, it plays with opam, requiring one to read a bunch of docs for opam, and its files, and where they should go.
- The syntax of the dune files changed a bit from when I started the project (it was just moving from jbuilder -> dune). Less of an issue now, though I still question the use of s-expressions.
- Can I load an interactive shell with the definitions? There's a command in the documentation for it, but it didn't work quite right when I tried.
- If you look at other projects, you'll see they use opam files differently from one another.
- How do I add a dependency in my current switch (something like npm --save install <library>?) I tried `opam install --deps-only`, but it complained sometimes about the state of uncommitted files.
I understand why it's like this (trying to tie together a ton of use cases) and love developing in it after it's all said and done, but there are a lot of rakes to step on.
(Just to avoid accusations of <whatever>: I actually discovered FP through OCaml and wrote a few early-ish libraries in the ecosystem, but then discovered Haskell... and the rest is history.)
Probably never going to use OCaml again (just for business reasons, nothing against it per se), but good info for other readers.
EDIT: I also hope some of the OCaml'ers did get some of use of the things I wrote. I'm not going to doxx myself by naming the exact things, but just wanted to say... I hope you took advantage of them because the stdlib was quite anemic, so you might want to extend it. They were just missing bits of the ecosystem that I wanted to be more convenient... and I implemented a data structure paper or two.
Having learned ML via Objective Caml's predecessor, Caml Light, ReasonML seems to be just sugar coating for those with aversion to ML classical syntax.
That’s exactly what it is, no secret about that, that’s the goal of that project.
Programing isn't poetry.
Of course all of this is highly subjective, but my understanding is that it's important to consider if you want highly successful projects.
Or Java and Kotlin / Scala.
Depending on how well an alternative syntax is requested and adopted by the existing ecosystem surrounding the particular VM, YMMV. Without knowing, I think you get quite different answers in each case.
The talk where he says this: https://youtu.be/5fG_lyNuEAw
[1] Yes, humans used to write machine code. By hand. Computers were for serious work, not mere clerical tasks such as translating mnemonic order codes to binary and doing address arithmetic.
First time I've heard a C-like syntax described as "poetic".
But the accumulation of @-signs, for example, seems to be a bit much.
So it's the Elixir to Ocaml's Erlang?
For people like you and me, we like the ML syntax and don't have too much need for a new one. But for many others, this may be the only way they will ever even decide to look at an ML. And hey–if after that they decide that they actually like the ML syntax better–well that's one of the 'secret' goals of Reason.
The first bad part is that Ocaml does not have a language spec. The implementation is the spec. This puts them at the whim of the Ocaml devs with no other options. SML is a standard with several good implementations.
Ocaml requires different operators for float and integer arithmetic. SML assumes an integer type unless you include a decimal. Both need to be replaced with module typeclasses (and both are working in that direction). For SML though, your existing code can continue to just work as it did before while Ocaml will be left with lots of `+.` or `*.` operators everywhere.
Another mistake that bleeds through is mutable strings. This is an outgrowth of all arrays being mutable. Immutable strings allow efficient representation as ropes instead of normal arrays (along with other optimizations that are good for GC'd languages). SML has immutable strings and vectors along with arrays (which you can still use as mutable strings of characters if you need them).
For their React-like goal though, Ocaml's lack of anonymous record types is the absolute worst. In SML, I can just type up a record and pass it in (no type definitions required). When passing in stuff to a component, you have to have all these named arguments. In SML, I'd just pass an anonymous record and destructure it in the function -- Just like in Javascript, but with types behind the scenes to keep everything straight.
Writing a custom parser for Babel like typescript or coffeescript have done would have been better for the language design and independence.
>For their React-like goal though, Ocaml's lack of anonymous record types is the absolute worst.
The object system actually allows this to be fair & it does get a little bit of use in some Reason libraries targeting React developers
I get that SML has advantages over OCaml but I don't really get what you're trying to argue for. Clearly if you like SML you'd prefer OCaml to JavaScript...
[1] https://caml.inria.fr/pub/docs/manual-ocaml/language.html
OCaml strings are immutable by default since OCaml 4.06.
The title ("Programming A Space Invader In OCaml and OpenGL: Lessons Learned") still fits with the content, don't you think?
https://github.com/marmelab/react-admin
I'd love to see an official Marmelab adapter so I can build my admin interfaces with ReasonML.
> And although some tools exist to make our life easier, they are poorly documented
Seems like author choose something poorly documented. Dune build system [1], opam [2] and esy [3] package managers are very well documented.
[1] https://dune.readthedocs.io/en/stable/
Submitted title was "Is ReasonML good by itself or the underlying OCaml the source of awesomeness?"
1) places features diverged
2) modules
3) F#'s "light" syntax mode
None of these really seem like Reason at all. Do you have any specific places where they're similar?
dnf install ocaml ocaml-lablgl-devel
?Anyway here's a toy game I wrote in GL + ODE + OCaml years ago: https://github.com/fccm/OCamlODE/blob/master/examples/katama...
Once you feel you have that sussed - it shouldn't take too long - pull up ReasonML and give it a go. Use the Bucklscript-Tea library - the architecture will be familiar from Elm.
Then give Reason-React a go.
Once that itch has been scratched move on to PureScript for a whole new rabbit hole to fall down.
Reason still hasn't had its async story ironed out, and has poor support for Unicode[0]
[0] "ReasonML strings are encoded as UTF-8 and not compatible with JavaScript’s UTF-16 strings" (from https://2ality.com/2017/12/basic-types-reasonml.html)
ReasonML/Ocaml is a general language. You can use whatever framework and platform you like. There is an Elm framework for Elm like development, there is a React layer for coding against react. But you can also write server apps, command line apps, GTK etc..
If the goal is some kind of syntax on top of JavaScript, I have no opinion.
The main difference is, Elm is like a drastically simplified version of Haskell, while Purescript is essentially Haskell with benefits (row polymorphism).
I thought the ocaml stdlib was relatively small though?