2 ms·
I've been using of BuckleScript and OCaml for a couple of years now. I'd been using OCaml for a long time before then. I tried ReasonReact, and found that I pre
by dpwm 7y ago
I've been using of BuckleScript and OCaml for a couple of years now. I'd been using OCaml for a long time before then. I tried ReasonReact, and found that I preferred the OCaml + vdom library way.
I first used my own minimal bindings to Mithril, but then later moved to an Elm Architecture implementation for bucklescript: bucklescript-tea. After being on a deadline and either completely misunderstanding or finding significant show-stopping bugs in bucklescript-tea's virtual dom implementation, I reimplemented the parts of the API I'd used from bucklescript-tea with a minimal alternative that called out to snabbdom for the vdom stuff. This was mainly as a learning exercise, which took all of about two afternoons of fairly relaxed work.
The only places I have needed to use annotations with this approach is in my modules that call out to JavaScript. This is really unavoidable, and you'd surely find the equivalent information would have to be provided if you used F# or PureScript, or your compiler simply won't know the types.
I'm sure my approach, with layers on layers of functions to build virtual dom nodes, is certainly not going to win any benchmarks, and it's certainly not novel – but it's good enough, and my productivity is up. I can leave a project for months and be relatively unsurprised by what I find when I return – because there's usually only one sensible way to do things. Everyone's different, though, and I fully respect it may not work for all.
The key lesson I've learnt is that interop is painful because the some of the bucklescript types do not neatly map how you would necessarily imagine to javascript types. But if you do this at the edges, and write sufficient wrappers, you won't have any problems.
The biggest pain point for a while has been that bucklescript is based on an old version of OCaml – and there have been some very nice additions to the OCaml standard library since then. That said, I think it's excellent that we've got two OCaml -> JS pathways in the OCaml world now.
- yawaramin 7y agoJust fyi– bs-platform 6 and above are based on OCaml 4.06. So, still not the latest, but a bit more recent! In particular, it supports record types directly embedded in variant constructors without having to declare them first.