OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of December 22 to 29, 2020.

Table of Contents

ppx_deriving_yaml 0.1.0

Patrick Ferris announced

I'm proud to announce the first release (and my first release) of ppx_deriving_yaml. If you are familiar with the excellent ppx_deriving_yojson then this library should come as no surprise. In fact it helped me a lot in writing this ppx, so thank you to its creators/maintainers.

Installation

$ opam update
$ opam install ppx_deriving_yaml

Usage

Ppx_deriving_yaml converts your OCaml types to the "basic" OCaml Yaml value type (the one that is currently compatible with ezjsonm). So for example you can have:

type t = { title: string; authors: string list } [@@deriving yaml]

let () =
  let v = { title = "Yaml PPX!"; authors = [ "Patrick Ferris" ] } in
  let yaml = to_yaml v in
  Yaml.pp Format.std_formatter yaml;
  match of_yaml yaml with
    | Ok t -> Format.print_string t.title
    | Error (`Msg m) -> failwith m

The ppx generates two functions:

val of_yaml : Yaml.value -> t Yaml.res
val to_yaml : t -> Yaml.value

And when built with this dune file:

(executable
 (name main)
 (libraries yaml)
 (preprocess
  (pps ppx_deriving_yaml)))

The following output is generated:

title: Yaml PPX!
authors:
- Patrick Ferris
Yaml PPX!

The README contains some more information and the library is still a little rough around the edges, especially with error reporting, but I'm currently using it in a few places such as an "ocaml-ified" github actions library (ppx_deriving_yaml's test workflow was automatically generated with it :sparkles:). This is a nice example of how it can be used in a fairly straightforward way to generate OCaml versions of the many projects that use Yaml for configuration files.

Happy yaml-ing :)

A Heroku buildpack for OCaml

roddy announced

I wrote a Heroku buildpack for OCaml web apps that use opam/dune.

opam-dune-lint - keep opam and dune dependencies in sync

Thomas Leonard announced

We're pleased to announce the first release of opam-dune-lint. This little tool checks that every ocamlfind dependency listed in your dune files has the corresponding opam package listed as a dependency in your *.opam file(s).

e.g.

$ cd charrua
$ opam dune-lint
charrua-client.opam: changes needed:
  "tcpip" {with-test & >= 6.0.0}           [from test/client, test/client/lwt]
charrua-server.opam: changes needed:
  "ppx_cstruct" {with-test & >= 6.0.0}     [from (ppx), test]
  "tcpip" {with-test & >= 6.0.0}           [from test]
charrua-unix.opam: changes needed:
  "cstruct-lwt" {>= 6.0.0}                 [from unix]
  "ipaddr" {>= 5.0.1}                      [from unix]
  "tcpip" {>= 6.0.0}                       [from unix]
charrua.opam: OK
Note: version numbers are just suggestions based on the currently installed version.
Write changes? [y] y
Wrote "./charrua-client.opam"
Wrote "./charrua-server.opam"
Wrote "./charrua-unix.opam"

If your project generates the opam files from dune-project, then it will update your dune-project instead.

It can also be useful to run this in CI. It will exit with a non-zero exit status if anything needs to be changed. ocaml-ci runs this automatically as part of the "lint-opam" check.

Scirep, a utility for literate programming

Philippe announced

I wrote a utility called scirep to render a markdown file with OCaml code blocks as an HTML document, which provides some support for graphics. Here are some examples of generated documents: one based on vg, and another using owl-plplot.

It can also be used downstream of mdx as a markdown-to-html converter that detects pictures in the toplevel's standard output and renders them in the final document.

It is really a hack, and it is poorly documented, but I'm advertising it in case it might be useful to others.

Camel Calendar for 2021

Florent Monnier announced

I would like to share with you a camel calendar for 2021 in pdf with the nice theme from ocaml dot org.

It was generated from an ocaml script that you can find in this repo: svg calendar generator.

Several scripts are available, you can find some results on this web page.

At the beginning of 2020 I was searching for a free software to generate calendars in SVG that I could customise for my own use, but I was unable to install the Perl script that exists (it has a lot of dependencies and the error message when I try to install it didn't help us to find what's wrong with it).

This explains the design of these scripts, that are made to work without any dependencies and without any compilation. There's code duplication, but every script only need the ocaml interpreter to be run, so most people comfortable with the command line should be able to use it.

(I also tried to sell some on Etsy but didn't sold a single one.)

By default 12 languages are included in every script, but you can generate the calendars for more than 200 languages if you use these dates locales that come from the CLDR repository.

You can also switch monday first or sunday first.

These generators are provided under Zlib license.

I hope some will enjoy!

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.