OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of May 14 to 21, 2024.

Table of Contents

We Want Your Feedback on the odoc Developer Experience

Sabine Schmaltz announced

Hey all, 🧡🐫

the documentation team at Tarides is looking for input and feedback on odoc.

I would be super happy if everyone who uses odoc or would use odoc if it worked for them can drop an answer in this feedback form:

https://docs.google.com/forms/d/e/1FAIpQLSfpZHlnbQjWolAhKJvn41aT5QJc7Gb7uZJSdtTT7MZeAdyMow/viewform?usp=sf_link

Windows compiler support in opam 2.2.0~beta2

David Allsopp announced

On behalf of the entire opam team, but also with a personal sense of relief, I'm very pleased to announce that the process of upstreaming support for Windows OCaml to opam-repository in ocaml/opam-repository#25861 finally started on Friday!

There's a full blog post with details on how you can try this out now with opam 2.2.0~beta2. The TL;DR, assuming you have winget on your Windows system (open the Microsoft Store app and install the App Installer package from Microsoft if you don't) then you can issue:

winget install Git.Git

if you don't have Git for Windows and:

winget install opam

if you don't yet have the 2.2.0~beta2 binary. You must then launch a fresh Command Prompt / PowerShell session. For there, you can then run:

opam init git+https://github.com/dra27/opam-repository.git#windows-initial

or

opam init -a --no-git-location --cygwin-internal-install git+https://github.com/dra27/opam-repository.git#windows-initial

if you'd like to be asked fewer questions. There is a known and big pause when updating the repository. However, after a little bit of time (coffee, or a sword battle, if that's your thing), you should then be faced with a fully initialised opam with ocaml-base-compiler.5.2.0 installed for the mingw-w64 amd64 port of native Windows opam.

Things with depexts will likely not work: the blog post contains details on how to get started with PRs, but issues are also helpful.

The blog post covers what we regard as the "default use case" - that is a native Windows user expecting to use this new OCaml thing they heard about natively. i.e. not running in WSL or Cygwin or MSYS2 or any other "are you sure can't just install Linux on that?" approach.

However, all the other use cases matter too! You're meant to be able to run native Windows opam from your own Cygwin or MSYS2 mintty bash terminal; we are aiming for the opam 2.2.0 binary to be a drop-in replacement (apart from setting os-distribution to "cygwinports") for "OCaml for Windows" for legacy use with the "sunset" repository; you're meant to be able to provide your own Cygwin or MSYS2 installation if you really need to (and you really might!). But we do need help testing all of it 🙂

We anticipate one further beta of opam 2.2.0 by the end of the month. From the Windows perspective, this will fix a known bug in the environment variable handling (see ocaml/opam#5838) but will also hopefully straighten out the behaviour of opam init for some of these "non-default" use cases. We're then hoping to rocket towards a release candidate in June 🚀

Happy Windows hacking! Please open issues; please ask for further help; please have fun!

David, on behalf of the opam team.

OCaml Workshop 2024 at ICFP – announcement and call for proposals

Continuing this thread, Sonja Heinze said

One more update, this time about hybrid modalities: We now have the confirmation from sigplan (the organizers behind ICFP) that we'll have the same hybrid modalities as last year :tada: So in particular, speakers can give talks remotely via a Zoom call. We'll also make sure this time that the remote speaker can see the audience over the call. To promote a good atmosphere, communication and engagement, we do prefer to have most talks in-person, but remote talks will be most welcome as well. So, don't hesitate to submit a talk even if you can't make it in person.

Cheers, @Armaël and @pitag

PD: Once the time comes closer, we'll give detail on youtube live and discord links for remote attendance as well

Guillaume Munch-Maccagnoni then added

Thanks, this update about hybridity should also be true for the ML workshop.

Odoc syntax cheatsheet

Paul-Elliot announced

Hello!

I'm happy to announce the addition of a cheatsheet for odoc's syntax!

I hope it will make it less painful to learn or refresh yourself on the topic. The full syntax reference is still useful to have some details.

Have {b fun} :slight_smile: !

DkCoder 0.2 - Scripting in OCaml

jbeckford announced

The 0.3 version is now available. It has a publicly accessible https://github.com/diskuv/dkcoder so issues can be filed, and cohttp 6.0.0~beta2 is now bundled.

Most important, 0.3 was sufficient to build the real production service https://gitlab.com/diskuv/samples/devops/DkSubscribeWebhook. It has a Dockerfile and Docker Compose for easy deployment to production, and the Docker container is based on Google's https://github.com/GoogleContainerTools/distroless#readme for a "small" size (well, 100MB is not small but it is not big either). The only executable in the container is ocamlrunx (no /bin/sh, etc.). In an ideal world where I had more time the service would be embedded inside MirageOS instead.

Imandra SysML Transpiler Internship Opportunity!

Ben Bellick announced

I wanted to share an opportunity for a summer internship with Imandra!

If you're someone with an interest in writing production OCaml or using a battle-worn automated theorem prover in an industry setting, please apply!

It is based in Austin, TX.

You can find more details and apply here.

Thanks!

Bam - A property-based testing with internal shrinking

François Thiré announced

I am excited to introduce Bam, a robust and versatile property-based testing (PBT) library. Bam simplifies the process of testing properties across a wide range of randomly generated values, making it easier to identify and debug issues in your code.

Key Features

  • Monad-like Generators: Create new generators easily with a monad-like pattern that works seamlessly with shrinking mechanisms.
  • PPX Support: Automatically derive generators based on type descriptions. The customizable deriver ensures smooth integration into your codebase.
  • Tezt Integration: Integrates with the Tezt test framework, providing a user-friendly experience, especially notable in debugging scenarios.
  • Internal Shrinking: Various default shrinking strategies help efficiently pinpoint minimal counterexamples. Internal shrinking ensures that only 'smaller' values are used during the process, and this is done in a way that is compatible with the monad-like operators.
  • Custom Shrinking: Define custom shrinkers that work well with the existing shrinking strategies.

Installation

You can install Bam using opam:

opam install bam tezt-bam

Getting started

Here is an example to get you started:

open Tezt_bam

type t = Foo of {a: int; b: string} | Bar of int list [@@deriving gen]
(** The deriver creates a value [val gen : t Bam.Std.t]. *)

let register () =
  let property = function
    | Foo {a; b} ->
        if a > 1_000 && String.contains b 'z' then
          Error (`Fail "A counter-example was found")
        else Ok ()
    | Bar [1; 2; 3; 4] ->
        Error `Bad_value
    | Bar _ ->
        Ok ()
  in  
  Pbt.register ~__FILE__ ~title:"Simple example of bam" ~tags:["bam"; "simple"]
    ~gen ~property ()

let _ = 
    register ();
    Test.run ()

There are several more detailed examples in the repository to show you around the library.

Contributions

Contributions from the community are welcome! If you have ideas, bug reports, or improvements, feel free to share them!

Kakadu asked and François Thiré replied

Can it be compared to https://github.com/c-cube/qcheck/ ?

My work around Bam started after using "QCheck" and especially "QCheck2" quite a lot for the Tezos project.

With respect to QCheck, QCheck2 came with "integrated" shrinking allowing to derive automatically shrinkers for generators. This aim to simplify debugging when a counter-example is found, so that a smaller example is reported to the user.

However, this came with a cost:

  • Performance-wise, there was a regression from "QCheck", especially the time taken to report a counter-example because the shrinking process was taking a lot of time
  • At some point, we even faced an issue were the shrinking process never ended. We started to implement an ad-hoc shrinker but it was not working either and we never really figured out. The solution was to deactivate shrinking
  • There are other UX considerations: debugging can be tedious (especially "hello" debugging)

So basically Bam started as an experiment to understand shrinking and come up with something easier to understand and compose better. This is why bam relies mainly on monadic operators.

This makes the writing of generators easier, the shrinking is internal ensuring the shrinking won't create new value. If you use the mondic operator of QCheck2, last time I checked it was not the case. This is why to create a generator for a pair, it is recommended to use tup2 instead of monadic operators.

Using monadic-operators allows you also to have a smaller kernel that is hopefully easier to maintain.

I also developped the integration of bam with Tezt in a way to avoid currently pitfalls we had with QCheck2:

  • You can easily control the stopping condition of the test
  • The test can be easily run in parallel or in a loop mode to help you find a counter-example quicker
  • The runner can fail if not enough values were generated or execution was too long (likely due to a regression)
  • It captures the output, so that only the one for the counter-example printed is shown. This is very handy during debugging. Otherwise, it is quite tedious to understand which line comes from which attempt
  • It is easy to opt-out from shrinking if it takes too much time. Can be useful for a CI. Shrinking only needs to be executed locally (assuming the property is deterministic) with a given seed

I also had some fun trying to define shrinking strategies allowing you to skip elements in a list. This is very handy when your property is about running a scenario made of a list of actions (a use-case very close to the monolith library from François Pottier). In general the initial counter-example contains superfluous actions. Such a strategy allows you to remove them to easy the debugging.

I don't have concrete data to compare Bam with QCheck2 at the moment. Let me know if you have ideas to make an objective comparison between those two libraries.

Stitch - Note Managing for Unorganized Minimalists

Marc Coquand announced

Hey everyone!

I wanted to share a cli tool built in OCaml I've been working on, that was only possible with the help of the community. :slight_smile:

The tool is called stitch, and is a minimal note-managing tool that aims to be a good unix citizen. It allows you to take notes in whatever format/editor you want while spending minimal time organizing them.

I built it using Cmdliner, Notty and Shexp. I'm drafting a longer writeup to share the challenges and general experience, but in short all three libraries were a bit short on examples but ultimately excellent and very easy to work with. Afterward, packaging everything turned out to be a bit harder.

Some screenshots: overview, todo, full-notes.

And link to repo:

https://git.mccd.space/pub/stitch/about/

It's still in it's early days and the code-base is a bit messy. But I use it as my daily driver for notes. :slight_smile:

7 OCaml Gotchas

Dmitrii Kovanikov announced

Hi everyone! :wave:

I've been using OCaml for a while, and I'm quite enjoying the language. In my not-so-long journey, I discovered a few surprising OCaml behaviours, so I decided to share them with everyone in a blog post.

I hope it reduces frustration for newcomers when they see something unexpected for the first time!

Using OCaml on windows with WSL

PizieDust announced

When I got started in OCaml, my setup was basically a dual boot of Windows 11 and Ubuntu. I had a few issues setting up OCaml on windows at the time and started looking up WSL and if it was a good alternative (I really disliked having to dual boot always). So I wrote this article detailing exactly how I setup OCaml on WSL and have been using it for the past 12 months with no issues. So if you are looking to get started with programming in OCaml on windows, this article is for you.

How to setup OCaml on Windows with WSL

Note: opam 2.2 makes it a breeze using OCaml on windows natively so if you are particularly interested about using OCaml without WSL you should check it out.

Other OCaml News

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 to the caml-list.