OCaml Weekly News
Hello
Here is the latest OCaml Weekly News, for the week of September 26 to October 03, 2023.
Table of Contents
- An update from the ocaml-wasm organization
- Interesting OCaml Articles
- Batteries v3.7.1
- uri.4.4.0
- Outreachy December 2023
- queenshead: a British pub name generator
- OCaml behind the scenes: Exception
- A memory-polymorphic, polyglot implementation of SplDoublyLinkedList (as transpiled by Pholyglot 0.2-betachicken)
- Packages for making proof assistants
- Old CWN
An update from the ocaml-wasm organization
Jan Midtgaard announced
Summer and ICFP has passed since we announced the ocaml-wasm
organization in
July. Here we provide an
update from the wasocaml
and wasm_of_ocaml
compiler projects since then.
Introduction
WebAssembly (Wasm) is an attractive compilation target for OCaml, as it
holds promises of better web-performance than compiling to JavaScript and furthermore opens up for
running OCaml on new platforms. The ocaml-wasm
organization is a
joint effort between two Wasm-targeting compiler projects for OCaml:
wasocaml
- an FLambda-based backend for OCaml’s native code compilerwasm_of_ocaml
- a fork ofjs_of_ocaml
that consumes OCaml bytecode and emits Wasm instead of JavaScript
Both compilers depend on the proposed garbage collection (GC) extension to Wasm, which is available behind a flag in development versions of Chrome, Firefox, and Node.js. As a first news item, we are excited to share that the Wasm GC proposal has moved to stage 4. As a consequence Chrome is planning to enable the WasmGC extension in version 119, scheduled to release in November! :tada:
wasocaml
- @chambart presented
wasocaml
at the ML workshop in Seattle in early September in connection with ICFP’23- Here’s a video link to the recorded presentation
- The slides and the workshop paper are available from this page with more details about the compiler
- After having benchmarked
wasocaml
, it was noticed that V8 exceptions are too slow right now. The OCaml exception compilation strategy has been changed to avoid using the native Wasm ones for now. This will be turned back into proper Wasm exceptions when the engines improve.
wasm_of_ocaml
@vouillon has made solid progress on implementing run-time bindings, which means that
wasm_of_ocaml
can now
- compile
ocamlc
itself into Wasm - run the Bonsai tests and examples
Early benchmarks results are encouraging: Compiled programs typically run around 10-20% faster
compared to the js_of_ocaml
equivalent.
A more detailed status:
- Lots of runtime bindings have been implemented
- for even more parts of the OCaml
Stdlib
: bigarrays, weak pointers, ephemerons, marshaling/unmarshaling - for external packages:
base
,core
,ppx_expect
,ppx_inline_test
,time_now
,incr_dom
,alcotest
,base_bigstring
,core_kernel
,string_dict
,bigstringaf
,js_of_ocaml_patches
,ocaml-cstruct
,Zarith
- for even more parts of the OCaml
- A number of PRs to get
Wasm_of_ocaml
supported:- in
dune
ocaml/dune#8278 - in
gen_js_api
LexiFi/gen_js_api#173 - in
Brr
dbuenzli/brr#51 and - to improve the
js_of_ocaml
-wasm_of_ocaml
compatibility ocsigen/js_of_ocaml#1492
- in
- It is now possible to include JavaScript runtime files and to use JavaScript primitives from Wasm runtime code, reusing the
js_of_ocaml
linker. - Implemented Effect support through CPS transformation for comparison with the current JS promise integration implementation
- Updates contributing to the on-going Wasm GC ecosystem development:
- Make the legacy parser follow more closely the standard GC text format WebAssembly/binaryen#5889
- Update stringref text format WebAssembly/binaryen#5891
- Use the standard syntax for ref.cast, ref.test and array.new_fixed WebAssembly/binaryen#5894
- Fixed a V8 crash https://chromium-review.googlesource.com/c/v8/v8/+/4660286 and implemented a workaround in binaryen tools WebAssembly/binaryen#5799
- Fixed the binaryen linker
wasm-merge
to support exporting an imported module entry WebAssembly/binaryen#5813
Interesting OCaml Articles
gasche said
I had fun reading Playing with Caml Light on DOS, published today (it is not obvious from the title).
Batteries v3.7.1
UnixJunkie announced
Dear community,
Batteries is a community-maintained extended standard library for OCaml.
The latest version of batteries is now available in opam: v3.7.1.
This version mostly adds compatibility with ocaml-5.1.0 (thanks to @kit-ty-kate). Now, batteries relies on dune for compilation (thanks to Simmo Saan and Gabriel Scherer).
Many thanks to all contributors for this release!
Happy hacking, The batteries maintainers.
Here is the change log for v3.7.1:
v3.7.1 (minor release)
- fix CI tests (dune clean && dune build @src/runtest) #1121 (Simo Saan)
- fix documentation errors for BatSet, BatMap and BatSplay #1120 (Simmo Saan)
- compatibility with OCaml 5.1.0 #1117 (kit-ty-kate)
- bugfix impacting BatString.split_on_string #1112 (Guido Martinez, review by Francois Berenger)
- add batteries.unthreaded to dune file #1104 (Stephen Sherratt)
- add optional dependency to dune in opam file #1103 (Stephen Sherratt)
- Finish switch to dune #1098 dune build #1099 dune runtest (Simmo Saan, review by Francois Berenger)
uri.4.4.0
Calascibetta Romain announced
Yours truly is delighted to announce the release of Uri 4.4.0.
ocaml-uri
is a library for manipulating URIs in accordance
with RFC 3986. This announcement allows us to
clarify a breaking change in the interpretation of IPv6. Previous versions did not interpret
IPv6 in the host
part of the URI - we simply escaped the special characters. This version of uri
now interprets IPv6 addresses in the host
part. This implies a change in the library’s behaviour
which may have some impact on software using this library. This announcement clarifies this
“breaking change”.
The library is available from OPAM: opam install uri.4.4.0
. From what we have been able to
observe, this breaking-change does not have a direct impact on the ecosystem. The release went
ahead without any software being broken. However, we would like to warn you of such a change. The
issues are open if you notice any unwanted behaviour
in the library.
Outreachy December 2023
Deep in this thread, Sudha Parimala said
@nikochiko and I have proposed a project to develop a geometric creative coding library for OCaml. This is heavily inspired by joy – we had loads of fun hacking with it at Lambda Retreat (in Scheme) and want to pass it on to OCaml programmers, and learn a bit about creative coding in the process. Really excited to work on this. Outreachy applicants: Please don’t hesitate to get in touch with us if you’re interested to contribute. :)
Huge thanks to @pitag, @patricoferris and everyone involved, for their efforts to keep this thriving!
Sonja Heinze then said
As promised, here is the update/summary on this round’s projects. Just like last round, the OCaml community has signed up with four super cool projects again. Here are this round’s projects:
- Implement R*-tree in OCaml An R*-tree is a data structure designed for geospatial use, particularly to be queried for geospatial objects contained in a given box. It’s super nice to see the Geospatial ecosystem for OCaml thrive. Mentors: @patricoferris , @AryanGodara
- Implement a dark mode for OCaml.org It’s a very nice idea to have a common feature request as an Outreachy project! That makes the internship very gratifying for the intern. Mentors: @SaySayo , @punchagan
- Improve the GUI experience for OCaml users Together with trying out and possibly improving different GUI libraries in OCaml, that will entail writing a “Are we GUI yet” page on ocaml.org, similar to Are we web yet?. Those pages are super important, both to understand the current OCaml ecosystem ourselves and to give an overview to newcomers. Mentors: @gpetiot, @moazzammoriani
- Develop a geometric creative coding library in OCaml Such a cool idea, @sudha ! It combines functional programming with creativity and basic geometry. The idea is to encode and draw 2-dimensional geometric shapes in a functional style. It’s inspired by Python’s joy. Mentors: @sudha, @nikochiko
Even at the small risk of being annoying: This is a good time for everyone who might possibly be interested in mentoring to start thinking about a project for next round :)
queenshead: a British pub name generator
Raphaël Proust announced
Just because I could, it doesn’t mean I should have; and yet I did write an entirely unnecessary generator for names of British pubs.
$ opam install queenshead … $ queenshead The horse and goats
More details on this short blog post.
It was a good excuse to experiment with crunch
as a way to embed some data files in an OCaml
program. Turned out to be easy.
OCaml behind the scenes: Exception
Fabrice announced
To celebrate this talk now being publicly available, I’ve added a chapter that was not part of the original presentation!
This Backtraces
section aims to explain how backtraces are constructed for exceptions, so that
exceptions can be linked to the code location that raised them. It also gives enough details about
the implementation to justify the claims in Takeaway #5
about backtrace collection and
raise_notrace
.
It’s a bit technical, so I didn’t dive in all the details, but there’s certainly plenty to understand the technique used.
The updated slides can be found in the release page of the repository: https://github.com/fabbing/obts_exn/releases Feel free to ask me any questions if anything isn’t clear enough. :slightly_smiling_face:
A memory-polymorphic, polyglot implementation of SplDoublyLinkedList (as transpiled by Pholyglot 0.2-betachicken)
Olle Härstedt announced
Added some new features to my hobby compiler project, Pholyglot. :) Maybe nothing interesting from an OCaml perspective, it’s a pretty basic amateur home-made compiler system, nothing fancy. The weirdest aspect of it is that it outputs C-code that is also valid PHP-code, so called polyglot code (semi-readable).
Since I’m career-locked into PHP, I’m writing myself out of it with my own compiler.
Another motivation is a slight disappointment in recent languages, like Rust, which does not, according to me, adhere to the 80/20-rule - that the most common use-case should be easy, and that in 80% of cases, you don’t have to be fast, but you should be able to be fast (instead of forced to be fast). Hence the opt-out-of-GC experiment.
The current GC is just Boehm. Might be interesting to try with ref-count too. Proper tracing is out-of-scope for the project (too hard… and requires headers etc, can’t combine it with manual memory, afaik).
Main OCaml src is here: https://github.com/olleharstedt/pholyglot/tree/main/src/lib
Most recent blog post: http://olleharstedt.github.io/programming/2023/03/19/memory-polymorphic-spldoublylinkedlist-pholyglot.html
Packages for making proof assistants
Favonia announced
We are excited to announce the first release of asai 浅い on OPAM, along with new versions of algaeff and yuujinchou 友人帳. We also released bwd and mugen 無限 on OPAM earlier but didn’t make an announcement.
All these packages are part of our research project to dissect a typical proof assistant into composable components so that everyone can easily build a high-quality, usable prototype out of their type checker. It turns out that many components are useful for writing compilers, too. Here are our packages: (✅ means it’s on OPAM.)
- ✅ asai 浅い for compiler diagnostics.
- ✅ yuujinchou 友人帳 for namespaces and lexical scoping. See my TYPES 2022 talk for its design principles.
- bantorra for library management (still under heavy development and revisions)
- ✅ mugen 無限 for universe levels. See our POPL 2023 paper for a theoretic analysis of its design.
- kado カド for handling cofibrations in Cartesian Cubical Type Theory. This was also used for implementing unfolding control.
together with these more general-purpose packages:
- ✅ algaeff for well-known composable effects-based gadgets (e.g., state, reader, etc.)
- ✅ bwd for backward lists
We have a prototype system showing how these packages may be used together. Many packages have been used in our proof assistant cooltt, @jonsterling’s ✅ forester tool and Topos Institute’s polytt. We invite you to try out our packages the next time you want to build a proof assistant or compiler!
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.