After successfully installing OCaml and Ocaide plugin for Eclipse on a Mac, I now think it's straightforward, however, before I completely forget the pain involved in figuring out what goes where. I wanted to put down some pointers for noobies like me, in hope that it will save people some valuable time.
is a great spot for finding any information related to OCaml. Installing OCaml is no different, you can read all about it
. There is tons of very useful and detailed information that I highly recommend anyone who is interested in OCaml to check out. In this post I just summarize the steps it took me to get from zero to OCaml installed (hero!).
Now that you have OCaml installed, let's discuss IDEs.
[Update] As was pointed out by numerous stackoverflow posts like
this one , Eclipse IDE tend not to recognise environment variables. The
solution is to wrap the execution into a bash script. It works, however, I couldn't manage to make it work with the MacOS launch database. Even after the update of the Info.plist, Eclipse still won't recognise environment variables. At this stage, I run the script manually and it works.
Vim
[Update] VIM grows on me. If you are interest to configure VIM to use OCaml, please follow
these instructions by
@avsm.
Here is how my ~/.vimrc looks like:
execute pathogen#infect()
let s:ocamlmerlin=substitute(system('opam config var share'),'\n$','','''') . "/ocamlmerlin"
let g:syntastic_ocaml_checkers = ['merlin']
au BufRead,BufNewFile *.ml,*.mli compiler ocaml
execute "set rtp+=".s:ocamlmerlin."/vim"
execute "set rtp+=".s:ocamlmerlin."/vimbufsync"
execute ":source " . "/Users/Yan/.opam/system/share/vim/syntax/ocp-indent.vim"
You can then do some cool stuff as kindly shared
here by
Thomas Leonard:
Then you get some nice shortcuts:
\s switches between the .ml and .mli file
\c comments the current line / selection (\C to uncomment)
% jumps to matching let/in, if/then, etc (see :h matchit-install)
\t tells you the type of the thing under the cursor (if you compiled with -annot)
Thomas also adds
"Also, Vim can then parse the output of the compiler and jump to the correct location."
However, he doesn't say how to do that. I searched the web and eventually figured it out. So here is what you need:
- Makefile to compile you code
- Vim 7.4+ (earlier versions don't seem to support it.
- and the knowledge how to use vim's quickfix
Let's tackle these one by one:
1. Here is a sample of a Makefile:
NAME =
OCAMLBUILD = ocamlbuild -use-ocamlfind -classic-display
PACKAGES = -package -tag thread
all:
$(OCAMLBUILD) $(PACKAGES) filename.byte
clean:
rm *.byte
test:
$(OCAMLBUILD) $(PACKAGES) filename.byte
2. Make sure you have an updated version of Vim.
3. You can read the full documentation on it
here, or check this quick and what I thought I useful, summary provided by this
stack overflow answer - run:
make and then:
:copen " Open the quickfix window
:ccl " Close it
:cw " Open it if there are "errors", close it otherwise (some people prefer this)
:cn " Go to the next error in the window
:cnf " Go to the first error in the next file
That's all folks! Enjoy.