hamacs/ha-programming-ocaml.org
Howard Abrams 6d92980311 Migration from ~/other to ~/src
Why was it any other way?
2024-10-19 13:34:01 -07:00

4.2 KiB
Raw Blame History

Emacs OCaml Integration

A literate programming file for integrating the OCaml programming language.

Introduction

After reading Batsov's OCaml overview essay, I became intrigued with learning more about it. Like him, Ill probably start learning OCaml using the following resources:

As these installation instructions state, the primary binary to install is the package manager, like:

  brew install opam

Initialize the opam package database by running:

  opam init

The book suggests installing utop:

  opam install core core_bench utop

The book also mentions that opam comes with a user-setup package to install Emacs configs. You can install it as follows, along with some related packages:

  opam install user-setup tuareg ocamlformat merlin
  opam user-setup install

But I wont be doing that, as I can configure it.

Basics

I kicked off this code by following with these instructions from Batsov.

Use the tuareg package for OCaml programming:

  (use-package tuareg
    :mode (((rx ".ocamlinit" eos) . tuareg-mode)))

Use dune.el to edit Dune project files:

  (use-package dune)

Merlin provides advanced IDE features:

  (use-package merlin
    :config
    (add-hook 'tuareg-mode-hook #'merlin-mode)
    ;; we're using flycheck instead
    (setq merlin-error-after-save nil))

  (use-package merlin-eldoc
    :hook ((tuareg-mode) . merlin-eldoc-setup))

The flycheck package uses Merlin internally:

  (use-package flycheck-ocaml
    :config (flycheck-ocaml-setup))

If I get into utop, I can also setup some integration with it like this:

  (use-package utop
    :config
    (add-hook 'tuareg-mode-hook #'utop-minor-mode))