Ocaml Tools and Editors

I just got back into Ocaml(not a ‘real’ programmer but an enthusiast ) and I’m wondering what the community uses for editors and tools.

Myself, I use Vim with merlin/ocp-indent/ocp-browser and utop and opam and OcamlBrowser but I’m curious what others use and if there are any problems with the tools or any compatibility issues between tools.

Also… Does everyone else have problems deciding when and where to make types abstract and concrete in functors?

1 Like

Emacs + Tuareg + Merlin (+ ocp-indent) have done very well for me.

3 Likes

Your setup sounds reasonable. I use vim for editing with merlin, ocp-indent (automatic indentation while typing), ocamlformat (formatting via neoformat). utop + ocp-browser for exploring APIs. dune to build. All via opam of course! The combination works very well for me. I haven’t run into any major compatibility issues between these tools.

The current default ocp-indent indentation and ocamlformat indentation don’t line up perfectly but both tools are configurable enough to work around those differences and ocamlformat has a lot of new formatting configuration options coming which should make the two line up even more when configured to do so.

2 Likes

I tried (I mean really tried) to use Emacs and just couldn’t grasp the fundamentals of that editor. I think its beyond my modest means.

There is ergomacs which changes hotkeys to be more standart… And Evil mode which sets hotkeys to be more like vim

Its too late… I’ve been adsorbed into the Vim collective.

2 Likes

I never understand this kind of claim, which I see made in both directions. I know both editors and there’s very little difference in learning curve. If you can learn emacs you can learn vi, and if you can learn vi you can learn emacs.

Yes, but once you’ve absorbed vi it’s difficult (for me at least) to absorb emacs (both keyboard memory and general philosophy). The main thing I miss from when I attempted my experiments using emacs is slime. There’s probably an equivalent in vi but I doubt it would be as seamlessly integrated.

I use neovim and I’ve uploaded my config to my dotfiles repo. Not sure if it’s helpful to others, I had a bit of trouble getting the autocomplete stuff to work using ncm2 but it works great now.

1 Like

You can try deoplete-ocaml with Vim 8/NeoVim: its main benefit is that completion is asynchronous and does not block you from typing.
If you just want to try it out without configuring many things see my docker container: https://github.com/edwintorok/xs-opam-dev

2 Likes

I mostly write Reason these days and use Sublime with the LSP plugin and reason-language-server, both of which would work when writing OCaml. Works pretty well.

RLS supports the ocaml syntax now?

I know I’m a little late to the party but I would like to put in a good word for vscode. I don’t use vscode as my primary editor (that’s spacemacs + tuareg), but I took it for a spin recently and I was able to get first-class OCaml/Reason support as well as vim keybindings in under a minute with vscode’s one-click extensions. I was very impressed by the polish and would definitely recommend for enthusiasts who don’t want to screw around with configuration too much.

1 Like

I had to setup an OCaml editor for a person who is used to vscode-like tools.
I could quickly get basics features (autocomplete, error reporting and jump). But I was not able to get evaluation of OCaml expressions which is the minimum feature for a REPL.
Can you evaluate OCaml expressions in vscode?
In between, we chosed to have a try for him with ocaml-top which is fine to do the REPL job (but this tool intended for education has no editing features such as search-replace, files tree, debug-compile, etc. ). It’s great for beginners who wants to focus on the OCaml language without being exposed to emacs/vim learning.

What is your setup?

Concerning debugging and compilation, I know that these features are not available. But maybe there is an easy tweak for that?

As @bobbypriambodo promoted vscode in his article about Dune, maybe he can tell to all of us more about that?

1 Like

Unfortunately I cannot say a lot on this subject since I use vscode very rarely (only when I break emacs really hard). I took a quick look around just now and it seems like it’s possible since vscode 0.8.0, which added debugging features which would allow utop to be integrated with vscode. There’s even this deprecated plugin which claims to have utop integration. Unfortunately the official ocaml/reason plugin does not appear to have support for this feature, and it looks like the currently recommended strategy is to invoke the repl via the embedded terminal. I imagine this setup is good enough for the majority of users.

It looks more like a workaround than a strategy.
As @freebroccolo says in the page you mentioned Support for connected rtop session. #43

a REPL integration will never work well without support from the build system or quite a bit of manual intervention from the user (load the right packages via topfind/Findlib).

Maybe the Dune team could give us their opinion about that?

There is an article about a projected OCaml IDE at JS but focused on github integration [Jane Street Tech Blog - Putting the I back in IDE: Towards a Github Explorer](http://Putting the I back in IDE: Towards a Github Explorer).

There is typerex that claims to be an OCaml programming studio but this is a set of (used) tools and not an IDE as suggested by the word studio.

I had a try a few years ago with the now old OcaIDE plugin for Eclipse that was interesting. It has module and members completion, code outline, type pop-ups, information pop-ups, hyperlinks, help on expected parameters, files tree, errors markers in the editor and in the files tree/explorer, module browser and integrated toplevel.

Try to remap your keyboard to dvorak, and to change the locations of control and alt keys. This works really well with regular physical keyboard. Also, check out http://ergoemacs.org/emacs/emacs_kb_shortcuts_pain.html, on the site mentioned earlier by by @Kakadu.

I am working on upstreaming some OCaml and Dune syntax improvements into the mainline Vim and Neovim, see vim-ocaml issue #33. So any feedback is appreciated.

Update: all changes that can be upstreamed (are part of the Vim) are now upstreamed.

1 Like