OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of January 10 to 17, 2023.

Table of Contents

Installing Windows OCaml 5.0.0 in opam

David Allsopp announced

One of opam 2.2’s headline features is that both “upstream” opam (i.e. opam built from un-patched sources from ocaml/opam) and “un-forked” opam-repository (i.e. ocaml/opam-repository) finally provide native Windows opam switches. We’re aiming to get an alpha release of this out in the coming weeks, but I’ve had various requests directly for how to use OCaml 5.0 with opam-repository-mingw in the meantime, so I’m just sharing this temporary solution, in case it’s of use to others.

I have a demonstration workflow at https://github.com/dra27/ocaml5-ci-demo with setup-ocaml. It shows the commands necessary for local use:

      - run: opam repo add dra27 git+https://github.com/dra27/opam-repository#windows-5.0 --all --set-default
      - run: opam switch create 5.0 --packages=ocaml.5.0.0,ocaml-option-mingw
      - run: opam exec --switch=5.0 -- ocamlopt -config
      - run: opam install --switch=5.0 utop

and also how to use it directly in a workflow:

      - name: Set-up OCaml
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: ocaml.5.0.0,ocaml-option-mingw
          opam-repositories: |
            dra27: https://github.com/dra27/opam-repository.git#windows-5.0
            default: https://github.com/fdopen/opam-repository-mingw.git#opam2

The windows-5.0 branch adds just enough to provide the OCaml 5.0.0 package for mingw-w64 by patching ocaml-variants.5.0.0+options (rather than providing ocaml-variants.5.0.0+mingw64). Unless you expressly select ocaml-variants.5.0.0+options, it’ll actually pick up a version patched with ocaml/ocaml#11846.

The only change once the alpha release comes out should be the removal of the opam repo add dra27 part.

Release of Mehari 0.1

Tim ats announced

@artichaut and I are very pleased to announce the first release of Mehari.

Mehari was created with the aim of offering a cross-platform framework to create Gemini applications.

Gemini is a lightweight alternative protocol to HTTP and Gopher, which runs on top of TLS.

On the “Geminispace”, there are mainly static content like blogs and other applications like games, BBS, etc.

Mehari API’s is largely inspired by Dream: it consists of a single module, and is pretty similar, there are handlers, routes, middlewares, etc.

Among the features, there are:

  • Cross-platform: the library provides many IO modules (Lwt, Mirage, Eio)
  • MIME type inference (using experimental Conan support)
  • Rate limit : it is easy to rate limit access to a route or to the whole server
  • Virtual hosting : hostname verification with SNI or request URL
  • Proxy: Ability to act as a proxy
  • CGI support with environment variables
  • Long-running TCP connection : incremental creation of the response body

Examples of use are available on the GitHub repository.

Documentation is available online with a short tutorial explaining the basics.

Currently, the library is in its infancy, the API is subject to change, so we are open to feedback and contribution, especially in terms of security.

Mehari is our first MirageOS-compatible library, so the creation of unikernels is experimental, and we’d love to get feedback on it.

Outreachy Summer 2023

Patrick Ferris announced

Yep, it’s that time of the year again! Outreachy has officially started asking for organisations and mentors for the Summer 2023 round.

What is Outreachy?

Outreachy is a paid, remote internship program. Outreachy promotes diversity in open source and open science. Our internships are for people who face under-representation, and discrimination or systemic bias in the technology industry of their country.

Given the long discussion in https://discuss.ocaml.org/t/what-are-the-biggest-reasons-newcomers-give-up-on-ocaml/10958 I can guarantee you that if you want some more really good answers, participating in Outreachy is one way to do that!

To help get a feel for what is to be a mentor, Outreachy will be holding a livestreamed call with previous mentors taking part which should be available on peertube (I’ll post links when available).

Important Dates

  • Jan. 17 at 3pm UTC - Mentor chat on YouTube and PeerTube
  • Feb. 6 at 3pm UTC - Mentor chat on YouTube and PeerTube
  • Feb. 10 at 4pm UTC - Deadline for open source and open science communities to sign up to be an Outreachy mentoring organization
  • Feb. 24 at 4pm UTC - Deadline for mentors to submit project descriptions for May 2023 interns to work on

This round

We had some excellent proposals for projects working on the compiler but unfortunately in the end no intern was found for it, please don’t be disheartened by this and I hope to see more projects suggested.

I’ve had the great fortune of working with Prisca on ocaml-topojson which has come on leaps and bounds thanks to her work! We’ll have a proper debrief towards the end of the project like the previous two rounds, although it may be a little shorter given the OCaml community only has one intern this round.

The older, but still relevant post https://discuss.ocaml.org/t/become-an-outreachy-mentor-support-the-growth-and-diversity-of-the-ocaml-community/8213 contains some more information about being a mentor which you may want to take a look at.

Please uses this thread for any questions, ideas or thoughts. Thank you :camel: !

Patrick Ferris later added

Friendly reminder the live chat will take place on https://diode.zone/a/outreachy tomorrow (17th Jan. 2023) at 3pm UTC. Whilst primarily focused on helping prospective applicants, it is still super useful for mentors to understand the process to help them out when the time comes.

Petrol 1.0.0 - A high-level typed SQL API for OCaml designed to go fast!

Kiran Gopinathan announced

Heyo! Pleased to annouce the release of a new library that I’ve been working on for some personal projects, but thought might be useful for others.

Petrol is a Free software library that provides a high-level OCaml API for interacting with SQL databases. The aim of this interface is to provide a type-safe API to allow developers to define their SQL tables and queries directly in OCaml, thereby avoiding the impedence mismatch and fragility that comes with having to directly write SQL code, as is typical in a normal Caqti-based project.

open Petrol

(* define a new schema *)
let schema = StaticSchema.init ()

(* declare a table *)
let example_table, Expr.[name; age] =
    StaticSchema.declare_table schema ~name:"example"
    Schema.[
        field "name" ~ty:Type.text;
        field "age" ~ty:Type.int
    ]

Petrol’s DSL allows you to express complex SQL queries as simple OCaml function compositions:

(* create a query *)
let insert_person ~name:n ~age:a db =
    Query.insert ~table:example_table
        ~values:Expr.[
            name := s n;
            age := i a
         ]
    |> Request.make_zero
    |> Petrol.exec db

Another selling point of Petrol is that it comes out of the box with a versioning system to gracefully allow changing the schemas in your application over time - this and more is described in the documentation.

https://github.com/gopiandcode/petrol

Anyway, as usual, I’ve tried to spend some quality time tuning the documentation to make it as easy to pick up as possible, so feel free to have a gander: https://gopiandcode.github.io/petrol/petrol/index.html

ocaml-search 0.1.1 - In-memory Search Index for OCaml values

Patrick Ferris announced

I’m happy to announce the release of a little OCaml library for doing in-memory searches over OCaml values: ocaml-search.

Here’s a quick example:

module Book = struct
  type t = {
    title : string;
    author : string;
  }
end

let books : Book.t list =
  [
    { title = "Dune"; author = "Frank Herbet" };
    { title = "The Day of the Triffids"; author = "John Wyndham" };
    { title = "The Remains of the Day"; author = "Kazuo Ishiguro" }
  ]

module Mono = Search.Tfidf.Mono (Search.Uids.String) (Book)
let search = Mono.empty ()

You can then add an index to your search index along with the documents.

Mono.add_index search (fun t -> t.title);
List.iter (fun doc -> Mono.add_document search doc.Book.title doc) books

Before finally being able to search.

Mono.search search "day";;
- : Mono.doc list =
[{Book.title = "The Remains of the Day"; author = "Kazuo Ishiguro"};
 {Book.title = "The Day of the Triffids"; author = "John Wyndham"}]

The README provides more thorough documentation and also explains how it can also provide a heterogeneous search index should you want it. I have plans to make the library more easily extendible with your own search strategies, but thought the initial TF-IDF implementation might already be useful.

This library is heavily inspired by js-search without which it wouldn’t exist.

Happy Hacking :camel:

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.