OCaml Weekly News
Hello
Here is the latest OCaml Weekly News, for the week of November 21 to 28, 2023.
Table of Contents
- Riot v0.0.3: an actor-model multi-core scheduler for OCaml 5
- Caper 0.9
- OCaml User Survey 2023
- Set up OCaml 2.1.2
- OCaml.org Newsletter: October 2023
- dream-html 1.2.0
- New Draft Tutorial on Polymorphic Variants
- Ppxlib dev meetings
- varray 0.2
- First release of
urn
: Urns for fast functional random sampling - Draft Tutorial on Mutability, Loops, and Imperative Programming
- First release of pretty_expressive: A Pretty Expressive Printer
- Other OCaml News
- Old CWN
Riot v0.0.3: an actor-model multi-core scheduler for OCaml 5
Archive: https://discuss.ocaml.org/t/ann-riot-v0-0-3-an-actor-model-multi-core-scheduler-for-ocaml-5/13463/1
ostera announced
Hi folks! :wave: wanted to share something I’ve been working on these last few weeks.
Riot is an actor-model multi-core scheduler for OCaml 5. It brings Erlang-style concurrency to the language, where lightweight processes communicate via typed message-passing.
Why Actors?
It raises the abstraction of multi-core so you don’t have to think about threads and low-level multithreading primitives, and instead can focus on structuring your application in terms of hierarchies of processes that do some work, and how they communicate with each other.
Erlang (and by extension Elixir) has been doing this for impure functional programming for decades now and in my experience it is an incredibly productive way of working. So I’m hoping to establish the foundation for doing this kind of application development but with types.
NB: This is the dual of the Caramel project, which is an alternative backend for OCaml that compiles to Core Erlang, thus letting you run some OCaml on the Erlang VM.
Getting Started
You can get started with: opam install riot
- Hello world
The simplest Riot program you can write is this:
Riot.run @@ fun () -> print_endline "hello world"
But there’s a small caveat here: this program doesn’t terminate.
Riot, like the Erlang VM, is designed for long-running applications. Despite this, it starts up reasonably fast (
4ms on a 10-core M1 Max). To terminate the runtime we must call ~Riot.shutdown ()
.The smallest Riot program is then:
Riot.(run shutdown)
Hello world, with messages!
The next smallest Riot program you can write is a hello-world that uses Processes and Messages:
open Riot type Message.t += Hello_world let () = Riot.run @@ fun () -> Runtime.Log.set_log_level (Some Info); let pid = spawn (fun () -> match receive () with | Hello_world -> Runtime.Log.info (fun f -> f "hello world from %a!" Pid.pp (self ()))) in send pid Hello_world
Hello world, with applications
Once you want to start building applications with supervision trees, to nicely decouple the subsystems of your app, you can use the
Application
interface, and Riot.start ~apps
:
module My_app = struct let start () = let pid = spawn_link (fun () -> (* ... do work! ... *)) in Ok pid end Riot.start ~apps:[ (module Riot.Logger); (* we want to start the logger app first *) (module Riot.Telemetry); (* we then start the telemetry app *) (module My_db); (* then start the database server *) (module My_app); (* finally we start our app *) ] ()
Next Steps
If you’re interested in trying Riot, I’ve started working on a tutorial that starts from zero and works its way up. It’s not complete yet but it should get you up and running and building interesting programs!
I’d love any feedback y’all have about this :) especially interested in what would you like to build with it or what libraries you’d like to use in this space.
Also happy to answer any questions :D
/ Leandro
Caper 0.9
niksu announced
Caper has reached v0.9. It is a tool for understanding and processing “pcap expressions” (also known as tcpdump filters) which are used for network packet analysis. It is entirely written in OCaml and includes pcap analysis logic, a from-scratch BPF compiler, and conversion to/from English expressions.
You can use Caper online through the BPF Exam site.
Caper’s README contains motivation, building, and usage examples, and its CHANGELOG describes recent updates.
A huge thanks goes to Caper’s contributers. Further contributions and feedback are welcome – a list of contribution ideas is included on Caper’s web page.
OCaml User Survey 2023
Kim Nguyễn announced
Hi everyone,
we are delighted to announce the OCaml User Survey, 2023 edition. With this survey, the OCSF is trying to get a better picture of the OCaml community and its needs. It would be very helpful if you could take a few minutes (10 to 15) to fill the survey and share it with other OCaml programmers.
https://forms.gle/iteoR7QMzFXw2mp89
The survey is run by the OCaml Software Foundation . It builds on previous iterations. The results will be published here on discuss and on the website of the OCSF . The OCSF would like to thank all the people that have helped in devising this or previous versions of the survey. Don’t hesitate to give us your feedback (you can post here or send me a message/email).
The survey will remain opened until December 8th 2023 (AOE). Please take the survey and don’t hesitate to share the link!
Some remarks regarding this year’s survey:
- Most of the questions are similar to the ones in the previous survey, some have been fixed, some have been updated (e.g. to list more recent versions of the OCaml compiler)
- A new section at the end on Demographics, Diversity and Inclusion. The related questions are more personal but again completely optional and would greatly help us get a better picture of our community and areas were the OCSF can help improve things
- Again, we resorted to using Google Forms. I spent quite some time trying to find a viable alternative, but none were satisfactory (either from a technical, accessibility or bureaucratic point of view). I understand that this can be a disappointment for some. If you are interested in running the survey next year on behalf of the OCSF, get in touch!
Set up OCaml 2.1.2
Sora Morimoto announced
This release contains a workaround for an upstream issue that is causing post process to become incredibly slow. If you would like to access related information, check out the PR. https://github.com/ocaml/setup-ocaml/pull/724
OCaml.org Newsletter: October 2023
Sabine Schmaltz announced
Welcome to the October 2023 edition of the OCaml.org newsletter! This update has been compiled by the OCaml.org team. You can find previous updates on Discuss.
Our goal is to make OCaml.org the best resource for anyone who wants to get started and be productive in OCaml. The OCaml.org newsletter provides an update on our progress towards that goal and an overview of the changes we are working on.
We couldn’t do it without all the amazing OCaml community members who help us review, revise, and create better OCaml documentation. Your feedback enables us to better prioritize our work and make progress towards our goal. Thank you!
This month, our priorities were:
- Learn Area: We continue our efforts to make OCaml.org a great resource for learning OCaml. This month, we’ve validated a new version of the designs for the Learn area, and we’ve published two new documentation pages!
- Outreachy Internship Application Period: OCaml.org is participating in the Outreachy Internship Program with two internship projects. As part of the application period, we’ve received tons of fantastic contributions from Outreachy applicants!
- General Improvements: As usual, we also worked on general maintenance and improvements based on user feedback, so we’re highlighting some of our work below.
Learn Area
- 1. Redesign of the Learn Area
After going back to the drawing board on the new designs for the Learn area, we’ve designed a new version of the landing page, alongside updated variants of the Community and Package landing pages, to ensure they are visually consistent. We’ve validated the new design direction and will be updating the designs for the rest of the Learn area pages next. Once the designs are available for all the pages, we’ll be ready to start implementing them. We’re very excited to get the new version of the pages live; we hope you are too! Stay tuned!
Learn Community Package Relevant PRs and Activities:
- Continued work on Figma UX/UI designs for the new Learn area
- Books page redesign - ocaml/ocaml.org#1536
- Added a short description to all exercises ocaml/ocaml.org#1681
- Collapse tab navigation to breadcrumbs for mobile view on learn area - ocaml/ocaml.org#1541
- 2. OCaml Documentation
Last month, we announced the publication of the new Get Started documentation. After publishing this section, we’re turning our focus to the Language section of the documentation.
This month, we’ve published two new documentation pages: Basic Data Types and Functions & Values. Together, they teach the basics of OCaml from the very beginning, starting with what a value and a function are. Having witnessed newcomers such as Outreachy interns struggle to learn OCaml from the OCaml.org documentation because it required a lot of prior programming knowledge, we’re excited to have this new content available for Outreachy interns and all newcomers. This is a first version of the pages, and we’ve already received excellent feedback to improve it. Don’t hesitate to share more, whether you’re a beginner struggling to get up and running, or an OCaml developer with opinions on how we should teach OCaml!
We’re currently reviewing two other documentation pages on Mutability and Polymorphic Variants. They should be ready for community review soon.
Stay tuned, and please, keep the feedback on the new documentation coming; it’s been a blast to see so much engagement from the community!
Relevant PRs and Activities:
- In Progress:
- Sets
- Maps
- In Review (internal):
- In Review (community):
- Published:
- Basic Data Types (see Discuss Thread)
- Functions and Values (see Discuss Thread)
- Installing OCaml (see Discuss Thread)
- A Tour Of OCaml (see Discuss Thread)
- Your First OCaml Program (see Discuss Thread)
- Introduction to opam Switches
- Fix Homebrew Errors on Apple M1
- Operators
- Error Handling (see Discuss Thread)
- Arrays (see Discuss Thread)
- Sequences (see Discuss Thread)
- In Progress:
Outreachy
OCaml.org is participating in the Outreachy Internship Program. Outreachy provides internships to people subject to systemic bias and impacted by underrepresentation in the technical industry where they are living.
A substantial part of this month has been spent on creating issues, reviewing pull requests, and mentoring Outreachy applicants on the OCaml Discord server.
The contributions include small fixes, implementing Figma designs, and small feature additions. Notably, the OCaml Changelog now has an RSS feed, and some outstanding designs for the package area have been applied.
8 out of the 21 medium difficulty issues have been completed in October, while only 6 out of 30 simple outreachy issues remain open. For the remaining issues, we will support the contributors in finishing their work, and free any abandoned issues so that community members can pick them up.
Relevant PRs and Activities:
- Opened 30 simple issues tagged “outreachy”, and 21 issues tagged “outreachy-medium”
- Refactor + simplify learn layout in preparation for new footer - ocaml/ocaml.org#1590
- @ademolaomosanya contributed: Rearranged and changed links in footer - ocaml/ocaml.org#1616
- @IdaraNabuk contributed: Update Tailwind Configuration to Resolve Warnings - ocaml/ocaml.org#1620
- @oyenuga17 contributed: Add a RSS feed for changelog - ocaml/ocaml.org#1593
- @sophiatunji contributed: Renamed “problems” with “exercises” in filenames and codebase - ocaml/ocaml.org#1592
- @kalio007 contributed: Add a “Standard Library API” link to the mobile navigation menu - ocaml/ocaml.org#1600
- @RWUBAKWANAYO contributed: Fix search bar on medium-sized screens - ocaml/ocaml.org#1665
- @shyusu4 contributed: Fix jump to definition on in-package search for Safari - ocaml/ocaml.org#1634
- @FatumaA contributed: Fix horizontal scrolling on ocaml ecosystem section of homepage - ocaml/ocaml.org#1668
- @AndroGenius-codes contributed: Applied new design for Package Search Dropdown - ocaml/ocaml.org#1608
- @henilGondalia contributed: Applied New Styles to Package Documentation Module Navigation - ocaml/ocaml.org#1638
- @Girish-Jangam contributed: Paginate package search results - ocaml/ocaml.org#1657
- @sophiatunji contributed: Fixed js-of-ocaml link on home - ocaml/ocaml.org#1707
- @Burnleydev1 contributed: Add Abongwa’s summer internship info - ocaml/ocaml.org#1647
- @RWUBAKWANAYO contributed: Add link to English edition of the book “Développement d’applications avec Objective Caml ocaml/ocaml.org#1659
- @AryanGodara contributed:
- Add Blog Post for Outreachy Summer internship, Summer’23 - ocaml/ocaml.org#1649
- Add Blog link in the summer internship post - ocaml/ocaml.org#1703
- @mohdaquib171 contributed: Tutorial Bottom Section Styles (#1603) ocaml/ocaml.org#1617 - status: waiting for completion of another issue
- @IdaraNabuk contributed: Add Capability for a Book Entry to have Multiple Languages - #1666 ocaml/ocaml.org#1679
- @oyenuga17 contributed: Add a Jump To Top Button ocaml/ocaml.org#1702
- @sophiatunji contributed: Learn Area Footer Redesign - ocaml/ocaml.org#1645
General Improvements
This month, we’re welcoming 1 new contributor:
- @davesnx changes ’Unknown documentation status’ from
a
to aspan
- ocaml/ocaml.org#1628
Relevant PRs and Activities:
- We now log a message instead of crashing when failing to parse the opam file - ocaml/ocaml.org#1575
dream-html 1.2.0
Yawar Amin announced
Small addition to allow checking if a node or attr is ’null’ (i.e. empty). This can be useful when you get a node or attr passed in to your function and you need to decide what to render depending on whether it’s empty or not.
As a reminder, ’null’ or empty nodes and attributes are ones which are simply not rendered into the final HTML.
New Draft Tutorial on Polymorphic Variants
Cuihtlauac Alvarado announced
Dear OCamlers,
The OCaml.org continues working on new tutorials. We have a draft on polymorphic variants; we’d like your feedback on it:
- GH PR: https://github.com/ocaml/ocaml.org/pull/1531
- Online draft: https://staging.ocaml.org/docs/polymorphic-variants
Previously announced tutorials form a series.
- Installing OCaml
- A Tour of OCaml
- Your First OCaml Program
- Values and Functions
- Basic Datatypes and Pattern Matching
But this one is not intended to follow right after those. It is designed to be taken by people familiar with OCaml’s basics and willing to master polymorphic variants.
As a draft, it has gaps, most notably:
- The section on Performance Drawbacks needs to be strengthened
- An example inspired by @garrigue “Code reuse through polymorphic variants” paper is missing
Share your feedback here or in GitHub, but do not use the “Contribute” link at the bottom of the page.
Hope it helps
Ppxlib dev meetings
Continuing this thread, Sonja Heinze said
It was a nice and short meeting with @ceastlund and me. Here are the meeting notes: https://github.com/ocaml-ppx/ppxlib/wiki/Dev-meeting-21-11-2023
varray 0.2
art-w announced
Hello everyone,
I’m not so pleased to announce a bugfix release of the varray
package on opam. This library provides an implementation of dynamic arrays, which automatically resize as elements are added or removed from the array. It’s based on the really fun
paper
“Tiered Vectors: Efficient Dynamic Arrays for Rank-Based Sequences” by Michael T. Goodrich and John G. Kloss II. When I first heard about it, I could not resist implementing this datastructure because its algorithmic complexities are rather fancy:
O(1)
to get/set elements anywhere in the arrayO(1)
to add or pop an element at the front/back of the arrayO(ᵏ√N)
to add or pop an element anywhere in the middle of the array (for any k >= 1)
And because there’s a fun way of exposing the API using OCaml’s functors:
module One = Varray.Circular (* k=1 => O(N) complexity for insert/delete *) module Two = Varray.Root (One) (* k=2 => O(√N) complexity *) module Three = Varray.Root (Two) (* k=3 => O(³√N) complexity *)
More details on the github repo and the online API documentation (which includes a teaser for odoc upcoming search feature, thanks to @EmileTrotignon, @panglesd and the wonderful odoc team :heart: )
Yet, I never publicly announced the initial release of this package on opam… because I don’t think dynamic arrays are actually useful when programming in OCaml! Using integer indices to address elements is prone to “index out of bounds” bugs, so it’s rarely the right choice. If you do have a usecase for them, I would love to hear it :)
—
But ok, so, wait, why am I announcing it now? Well because @n-osborne found a bug in my code which could trigger a segfault! This terrible bug was only affecting the lesser-used
delete_at
operation, and so it lay dormant for two years. This was a very dumb mistake: This specific function was missing a check for out of bound indexes (ha!)
While I would prefer to avoid the public walk of shame, how the bug was discovered is too cool not to share: @n-osborne and @shym wrote a
Gospel specification of how the Varray library should behave, which enabled them to stress test it and discover a counter-example where my code was misbehaving. Here’s an extract of the faulty function specification,
where Gospel specs are written as special comments (*@ ... *)
in the mli documentation:
type 'a t (*@ mutable model contents : 'a sequence *) (* ^^^ Gospel modelization of the abstract varray type as a "mutable sequence called contents" *) val delete_at : 'a t -> int -> unit (** [delete_at t i] removes the element [t.(i)]. Every element on the right of [i] is shifted by one to the left. *) (*@ delete_at t i checks inside i t.contents modifies t.contents ensures t.contents = old (t.contents[..(i - 1)] ++ t.contents[(i + 1)..]) *)
Note the use of the keyword old
on the last line, which allows the postcondition
ensures
to refer to the state of the input before it was imperatively modified. Formal specifications are generally reserved to specialists, but look how readable this is! (see
the full varray spec)
Gospel specs can then be interpreted by a variety of tools. To discover this specific bug, @n-osborne used Ortac to automatically translate his specification into an executable QCheck-STM test to search for incoherencies between the model and the actual implementation.
Very very cool stuff. If you are looking for more resources on the subject, I found Chapter 2 of Clément Pascutto’s PhD thesis to be a very nice introduction to Gospel specifications :) (and later chapters describe his cutting edge research for Ortac!)
zapashcanon then said
For those speaking french and interested in Gospal/Ortac, there’s a video of Clément’s talk given at the oups meetup last year.
First release of urn
: Urns for fast functional random sampling
Justin Frank announced
Hi all! I’m pleased to announce the first release of urn a library that implements urns, a very nifty pure functional data structure for randomly sampling with or without replacement from weighted discrete distributions in log time. It provides implementations for using ~int~s and ~float~s as weights, though it can be extended to any number like thing that can be uniformly sampled from.
The package is available through opam with opam install urn
, and is distributed under the MIT license.
Draft Tutorial on Mutability, Loops, and Imperative Programming
Archive: https://discuss.ocaml.org/t/draft-tutorial-on-mutability-loops-and-imperative-programming/13504/1
Cuihtlauac Alvarado announced
Dear OCamlers,
The OCaml.org team has yet another draft tutorial. This time, the title is: “Mutability, Loops, and Imperative Programming”. We want your feedback on it:
- GH PR: Tutorial on Mutability and Imperative Programming
- Online draft: Mutability, Loops, and Imperative Programming
The target audience is developers learning OCaml. No functional programming knowledge is assumed. However, it comes after the “Get Started” series:
And it comes at the end of the “Introduction” series:
- Values and Functions
- Basic Datatypes and Pattern Matching
- If Statements and Recursions
- Lists
- Labelled & Optional Arguments
- Mutability, Loops, and Imperative Programming
As the previously announced draft on polymorphic variants this one contains overlooked issues. We want to make it better with your help.
Share your feedback here or in GitHub, but do not use the “Contribute” link at the bottom of the staging page.
Hope it helps
First release of pretty_expressive: A Pretty Expressive Printer
Sorawee Porncharoenwase announced
Hi everyone!
I am happy to announce the release of
pretty_expressive
, an implementation of
A Pretty Expressive Printer (OOPSLA’23).
- Documentation
- Project page
- opam:
opam install pretty_expressive
Unlike other pretty printers in the OCaml ecosystem which are mostly focused on the OCaml style (as far as I can tell),
pretty_expressive
is general-purpose, making it suitable for formatting various styles (the pretty printer was originally created to format programs in the Racket language).
pretty_expressive
is further distinguished from other general-purpose pretty printers (e.g., Hughes’, Wadler’s, Bernardy’s) by its expressiveness and optimality.
This is also my first OCaml project (not counting Reason). Any feedback is welcome!
Thanks, Sorawee
Other OCaml News
From the ocaml.org blog
Here are links from many OCaml blogs aggregated at 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 to the caml-list.