OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of September 06 to 13, 2022.

Table of Contents

Caqti 1.9.0 and Plans for 2.0.0

Petter A. Urkedal announced

First I would like to announce the 1.9.0 minor release, see the release notes below for details.

There is also ongoing work in the caqti2 branch targeted for the next major release. If someone have an opinion on directions, we can discuss it here, or in the issue tracker (meta-issue), see my brief notes below.

I will attend parts of the ICFP 2022 virtually next week so there may be time to discuss over audio.

Release Notes for 1.9.0

New features:

  • Allow unquoted semicolons in query strings in the new API. There are corner cases where it is needed, as reported in issue #87, and a parser which rejects semicolons are still available for loading schema files statement by statement.
  • Add support for MySQL and MariaDB configuration files, as a solution to issue #86.
  • Add a limit to the number of times a database connection is reused when pooling connections (#94). Thanks to Peter Mondlock for investigating resource usage server side motivating this addition.
  • Provide access to the raw SQLite3 connection handle for the purpose of defining custom functions (#56).

Fixes:

  • Add missing dune dependency on unix (GPR#85 by David Allsopp).
  • Documentation fixes (GPR#82, GPR#83, GPR#84 by Reynir Bj√∂rnsson, GPR#88 by Jonathan Duarte, and GPR#92 by Jim Tittsler).

Deprecations:

  • Caqti_type.field was deprecated in favour of Caqti_type.Field.t.

Other:

  • Replace deprecated core_kernel dependency with core.

Notes on 2.0.0 Development

The main addition is pgx and mirage support. It is already functional, but not very useful for production, since it lacks TLS. The trick here is that PostgreSQL uses STARTTLS, so we can’t use conduit-lwt as-is.

Another thing in progress, but unpublished, is per-connection configuration. Up till now, configuration has only been possible through the connection URL or behind-the-scene via C libraries (now also for MariaDB). However, this will no longer be practical for delivering CA certificates to pgx. Two design issues which you may have an opinion about:

  • Driver specific options can be defined in the caqti package or in caqti-driver-* packages. In the former case, the configuration can be manipulated without depending on specific drivers, but the downside is that we will pull in dependencies on x509, domain-name, ipaddr and possibly tls and sexplib0.
  • My current sketch provides sexp-serialisation, a choice mainly motivated by the availability of such serialization for client configuration of tls, but I hope to find a more generic solution which allows easy embedding of Caqti configuration in application configuration independent of which format is used.

An example of how an sexp-formatted configuration might look like:

(connection
 (pool
  (max-use-count 20)
  (max-idle-size 10))
 (driver postgresql)
 (endpoints
  (inet pg1.example.org)
  (inet pg2.example.org))
 (target-session-attrs read-write))

where the (pool ...) clause is driver-indepnedent and the (driver ...) clause determines which DB-specific options are valid. In the current draft, order does not matter despite this dependency.

(I could also mention plans of wrapping modules, but this will be done first as a forward-compatible module in parallel to the current modules preferably at the beginning of a major release cycle. The reason I haven’t written that main Caqti module yet, is that I would like to take the opportunity to tidy up the namespace to make it easier for newcomers to discover the main entry points.)

Outreachy summer ’22 closing commemoration session on 23rd Sept

Moazzam Moriani announced

I, along with Jay, were the two Outreachy interns working with the OCaml :camel: community this summer. I worked on Multicore Applications and Jay on TopoJSON. Our internship, of course, was only made possible because @sudha and @patricoferris generously chose to volunteer to mentor us–as our respective mentors–throughout the summer. We are grateful to the both of them :heart:.

Our three-month long Outreachy internship just ended relatively recently and, personally, I have really enjoyed working on my project and learning OCaml. So much so that Jay and I would like to share our experiences with the rest of the community. :sparkles:

To carry forward a tradition established by the previous Outreachy cohort, we will host a virtual session that will consist of two short presentations from the both of us followed by a Q&A. The session will be on Friday 23rd September 2-3pm CET.

It is open to whoever wishes to join. A recording will be shared later online as well.

We hope you will join us! :raised_hands:

Marcus Rohrmoser asked and Moazzam Moriani replied

I suppose you mean CEST i.e. 2022-09-23T14:00:00+02:00/PT1H

Yes I do. Thank you for pointing it out.

MirageOS for B2B SaaS

Volodymyr Melnyk asked

I have an idea to build a SaaS for corporate blogging (like Medium, but for companies) and I want to try MirageOS as a total platform for services. I have no production experience with OCaml (only Golang, JS, Ruby) and have no experience with MirageOS and unikernels (only Docker, Linux, and a little bit k8s), but I’m very interested in both. Could you please help me to clarify possible issues with such an approach?

Also I’m interested about a hosting for MirageOS services. I don’t like containers and k8s stuff and I prefer dedicated and virtual servers instead of cloud stuff because I have no resources to pay up to 5x more for hosting.

Thank you for your help!

Calascibetta Romain replied

Thank you for your interest in MirageOS. MirageOS is first and foremost a framework for creating an application (such as a blog) for several targets. One of these targets is Solo5 which allows to create an entire system which includes everything necessary for OCaml (its runtime). Thus, one can deploy a MirageOS application on:

  • KVM (with the target hvt)
  • Xen
  • or produce a simple executable taking advantage of seccomp (and thus finely controlling access to the executable).
  • we can also mention the experimental target for Raspberry Pi 4

The objective of MirageOS is to make the choice of targets transparent to the application. This means that for a given application, deploying for KVM or Xen should not be an upstream choice (which would govern the development of the application) but the last of the choices which can, of course, be left to third party users.

This reverses the development logic of an application thanks to abstraction mechanisms (specific to OCaml) (the functors) that allow to get rid of any specialisation to a given system (Solo5, Unix, Raspberry Pi, etc.).

This is of course the theory and in practice, it works quite well :) .

To take the example of the blog, you can see Hannes’ blog or mine which runs on MirageOS (KVM). The latter have a similar architecture: a unikernel managing TLS certificates and redirecting HTTP connections to unikernels on a local network (tlstunnel or contruno) and a unikernel (unipi) that only transmits what appears in a Git repository via the HTTP protocol (http/1.1 and h2).

Deployment depends of course on what you have. Regarding KVM, you can follow the tutorials here (quite general) and there. You can deploy your unikernels on Google Cloud with this (probably a bit old) tutorial. Finally, a deployment with seccomp is possible, it is a simple executable.

Of course, most of these unikernels are already available for download here thanks to the excellent work of robur.io. It is ensured that the generated image is reproducible regardless of the context.

There is of course a whole series of unikernels made by the community that you can mainly find on GitHub. We can talk about several services like DNS or emails.

I would like to specify that all this is still experimental. We are gradually reaching the stage where our unikernels are used in production domains, but it still requires a lot of work and a lot of skills for such a small team :) . Of course, we are open to everyone’s participation and we are especially here to help newcomers.

Tuareg and Caml modes for Emacs: what are the differences?

Deep in this thread, Tim McGilchrist announced

I wrote up a longer form version of my setup at https://lambdafoo.com/posts/2022-09-07-ocaml-with-emacs-2022.html There are still some bits I am not happy with but I have been using it daily. Also @bbatsov wrote his version at https://batsov.com/articles/2022/08/23/setting-up-emacs-for-ocaml-development/

Engineer position at Imandra (Austin TX/UK)

Simon Cruanes announced

Imandra is looking for a full time engineer in the UK or in Austin, Texas.

The job offers can be found here.Imandra is an AI startup developing a cloud-native automated reasoning engine for analysis of algorithms and data. Whether you’re writing mission-critical code or need to understand the countless complex decisions that a system may make, use Imandra to ensure the algorithms you create are safe, explainable and fair. OCaml is the main language used at Imandra.

Acme plumbing rules for OCaml

David A. Arroyo announced

I am sure that the intersection of OCaml users and Acme users is small, but I have reason to believe it is a non-zero set :) . For those of you using this spartan editor, here are some plumbing rules that I use that allow me to right-click on error messages returned by the OCaml compilers, and jump to the referenced location in acme:

# example: in file "foo/bar.ml", line 155, characters 30-62
type	is	text
data	matches	'.*[Ff]ile "([^"]+)", line ([0-9]+), characters ([0-9]+)-([0-9]+).*'$nl'?'
arg	isfile	$1
data	set	$file
attr	add	addr=$2-#0+#$3,$2-#0+#$4
plumb	to	edit
plumb	client	$editor

# example: File "tests/dune", line 2, characters 7-22:
type	is	text
data	matches	'.*[Ff]ile "([^"]+)", lines ([0-9]+)-([0-9]+).*'$nl'?'
arg	isfile	$1
data	set	$file
attr	add	addr=$2,$3
plumb	to	edit
plumb	client	$editor

It could probably be extended to search ~/.opam so you could plumb errors in files outside of your project, but I do not use opam, so I haven’t needed to do it.

Here is a short demo of its use: https://youtu.be/Evl-N0oNNd0

It’s not in OCaml, but I also wrote https://github.com/droyo/acme-autoformat and put an OcamlFmt script in acme’s $PATH like so:

#!/bin/sh
exec /usr/local/bin/acme-autoformat -r '\.mli?$' \
	-- ocamlformat --name='{{.Basename}}' --enable-outside-detected-project -

This calls ocamlformat whenever I Put an .ml[i] file. This is probably obviated by combining acme-lsp and ocaml-lsp, but these two bits work well enough that I haven’t felt a need to pursue it.

Other OCaml News

From the ocaml.org blog

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.