OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of June 18 to 25, 2019.

Table of Contents

PSA: ocaml/opam2 docker images updated to 4.08.0 release

Anil Madhavapeddy announced

The Docker images hosted at ocaml/opam2 have now been updated to include the latest OCaml 4.08.0 release as well as the snapshots of 4.09 and 4.10.

One sideeffect of this is that the ocaml/opam2 default image now has OCaml 4.08 as its default switch. If you use it in CI, it may suddenly give you errors if your code has not yet been ported to work with that new release.

As a reminder, you can pin the OCaml version you use in CI easily by:

  • running opam switch 4.07 as the first command in the Dockerfile after FROM ocaml/opam2.
  • using the ocaml/opam2:4.07 image instead of the default one. This image also includes several other 4.07.0 variants (such as afl, flambda and so on), which you can list with docker run ocaml/opam2:4.07 opam switch.

As always, please get in touch with me if you see any other breakage from these image updates.

Default key bindings for utop

Daniel Lim asked

Just getting into OCaml, and utop is really nice, but I can't seem to find any of the default key bindings listed anywhere online.

It took quite some time to find out C-p can be used to move to the previous lines, which was really needed when coming across multiline use cases like this:

let ratio x y =
  Float.of_int x /. Float.of_int y
;;

Is there anywhere that I can find the default key bindings for the repl?

Vladimir Keleshev replied

You can use #utop_bindings;; command in the prompt. Check out other useful #utop_* commands as well.

$ utop
────────────────────────────────┬─────────────────────────────────────────────────────────────┬────────────────────────────────
                                │ Welcome to utop version 2.3.0 (using OCaml version 4.07.0)! │
                                └─────────────────────────────────────────────────────────────┘

Type #utop_help for help about using utop.

# #utop_bindings;;
enter       : accept                        -> accept the current input.
escape      : cancel-search                 -> cancel search mode.
tab         : complete                      -> complete current input.
up          : history-prev                  -> go to the previous entry of the history.
down        : history-next                  -> go to the next entry of the history.
left        : prev-char                     -> move the cursor to the previous character.
right       : next-char                     -> move the cursor to the next character.
home        : goto-bot                      -> move the cursor to the beginning of the text.
end         : goto-eot                      -> move the cursor to the end of the text.
insert      : switch-erase-mode             -> switch the current erasing mode.
delete      : delete-next-char              -> delete the character after the cursor.
backspace   : delete-prev-char              -> delete the character before the cursor.
M-enter     : newline                       -> insert a newline character.
M-tab       : complete-bar                  -> complete current input using the completion bar.
M-down      : complete-bar                  -> complete current input using the completion bar.
M-left      : complete-bar-prev             -> go to the previous possible completion in the completion bar.
M-right     : complete-bar-next             -> go to the next possible completion in the completion bar.
M-home      : complete-bar-first            -> go to the beginning of the completion bar.
M-end       : complete-bar-last             -> go to the end of the completion bar.
M-delete    : kill-prev-word                -> cut the word behind the cursor.
M-backspace : kill-prev-word                -> cut the word behind the cursor.
M-b         : prev-word                     -> move the cursor to the beginning of the previous word.
M-c         : capitalize-word               -> capitalize the first word after the cursor.
M-d         : kill-next-word                -> cut up until the next non-word character.
M-f         : next-word                     -> move the cursor to the end of the next word.
M-l         : lowercase-word                -> convert the first word after the cursor to lowercase.
M-n         : history-next                  -> go to the next entry of the history.
M-p         : history-prev                  -> go to the previous entry of the history.
M-u         : uppercase-word                -> convert the first word after the cursor to uppercase.
M-w         : copy                          -> copy the current region to the clipboard.
C-left      : prev-word                     -> move the cursor to the beginning of the previous word.
C-right     : next-word                     -> move the cursor to the end of the next word.
C-delete    : kill-next-word                -> cut up until the next non-word character.
C-space     : set-mark                      -> set the mark to the current position.
C-_         : undo                          -> revert the last action.
C-a         : goto-bol                      -> move the cursor to the beginning of the current line.
C-b         : prev-char                     -> move the cursor to the previous character.
C-c         : break                         -> cancel edition.
C-d         : interrupt-or-delete-next-char -> interrupt if at the beginning of an empty line, or delete the next character.
C-e         : goto-eol                      -> move the cursor to the end of the current line.
C-f         : next-char                     -> move the cursor to the next character.
C-g         : cancel-macro                  -> cancel the current macro.
C-h         : delete-prev-char              -> delete the character before the cursor.
C-k         : kill-next-line                -> cut everything until the end of the current line.
C-l         : clear-screen                  -> clear the screen.
C-m         : accept                        -> accept the current input.
C-n         : next-line                     -> move the cursor to the next line.
C-p         : prev-line                     -> move the cursor to the previous line.
C-r         : prev-search                   -> search backward in the history.
C-s         : next-search                   -> search forward in the history.
C-u         : kill-prev-line                -> cut everything until the beginning of the current line.
C-w         : kill                          -> cut the current region to the clipboard.
C-x (       : start-macro                   -> start a new macro.
C-x )       : stop-macro                    -> end the current macro.
C-x e       : play-macro                    -> play the last recorded macro.
C-x C-e     : edit-with-external-editor     -> edit input with external editor command.
C-x C-k tab : insert-macro-counter          -> insert the current value of the macro counter.
C-x C-k C-a : add-macro-counter             -> adds a value to the macro counter.
C-x C-k C-c : set-macro-counter             -> sets the value of the macro counter.
C-y         : yank                          -> paste the contents of the clipboard at current position.
C-z         : suspend                       -> suspend edition.
#

You can also override these in ~/.lambda-term-inputrc. Here's what I have:

$ cat ~/.lambda-term-inputrc
[read-line]
C-p: complete-bar-prev
C-n: complete-bar-next

I overrode these to use Ctrl (C) instead of Meta (M) because with my setup (Mac Terminal.app) the meta character (which I would expect to be mapped to the Command key) doesn't seem to work.

Creating OCaml Platform

Anton Kochkov said

Everyone knows there is a Haskell Platform and Stack. And Rust is working with a similar concepts for a few years already. Maybe it makes sense to start working towards this goal in OCamlverse as well? The relevant thing is Duniverse by @avsm, but the platform concept should go further, helping to download the bundle at once, instead of installing hundreds of packages manually. I see there is actually a site page for the OCaml Platform, but it is basically empty.

It even makes sense to include Visual Studio Code with OCaml plugins installed.

Vasile Rotaru replied

As I understand it, is not there yet. See this talk by Anil Madhavapeddy (@avsm)

Other OCaml News

From the ocamlcore planet blog

Here are links from many OCaml blogs aggregated at OCaml Planet.

Old CWN

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.