OCaml Weekly News
Hello
Here is the latest OCaml Weekly News, for the week of May 16 to 23, 2023.
Table of Contents
Looking for example tsdl games
Benjamin Thomas said
This one is for the search engines…
I was looking for a way to setup a “proper” game loop, functional style.
Looking at the tsdl
repo, I noticed the examples in the test folder make heavy use of match expressions. Replicating that style quickly led me to a “callback hell” type of problem though.
Anyhow, this is my take on setting up a basic game loop:
(* * dune exec --display=quiet bin/main.exe *) module Sdl = Tsdl.Sdl module Window = Sdl.Window module Event = Sdl.Event let ( let* ) = Result.bind type error_ctx = | Partial of { window : Sdl.window } | Full of { window : Sdl.window; renderer : Sdl.renderer } (* Attach extra context to the original error. * Used for resource cleanup on program exit. *) let with_err_ctx ctx = Result.map_error (fun err -> (err, ctx)) let init_window () = let* () = Sdl.init Sdl.Init.(audio + video) in let* window = Sdl.create_window "OCaml/TSDL: CHANGE_ME" ~x:Window.pos_centered ~y:Window.pos_centered ~w:640 ~h:480 Window.shown in Ok window ;; let render_frame renderer (x, y) = let* () = Sdl.set_render_draw_color renderer 255 127 40 255 in let* () = Sdl.render_clear renderer in let* () = Sdl.set_render_draw_color renderer 255 0 0 255 in let* () = Sdl.render_fill_rect renderer (Some (Sdl.Rect.create ~x ~y ~w:70 ~h:70)) in () ; Sdl.render_present renderer ; Ok () ;; type state = { quit : bool; pos : int * int } let initial_state = { quit = false; pos = (0, 0) } let poll evt state = let (x, y) = state.pos in let default = { state with pos = (x + 2, y + 1) } in if Sdl.poll_event (Some evt) then match Event.(enum (get evt typ)) with | `Quit -> { state with quit = true } | _ -> default else default ;; let run_game_loop renderer = let rec loop evt state = if not state.quit then ( let state = poll evt state in let* () = render_frame renderer state.pos in () ; Sdl.delay 17l (* approx 60 FPS *) ; loop evt state ) else Ok () in let evt = Event.create () in loop evt initial_state ;; let start_game () = let* window = init_window () |> with_err_ctx None in let* renderer = Sdl.create_renderer window |> with_err_ctx (Some (Partial { window })) in let* () = run_game_loop renderer |> with_err_ctx (Some (Full { window; renderer })) in Ok (window, renderer) ;; let rec destroy_resources = function | Some (Full { window; renderer }) -> () ; Sdl.destroy_renderer renderer ; destroy_resources @@ Some (Partial { window }) | Some (Partial { window }) -> () ; Sdl.destroy_window window | None -> () ;; let () = match start_game () with | Ok (window, renderer) -> () ; Sdl.destroy_renderer renderer ; Sdl.destroy_window window ; Sdl.quit () ; exit 0 | Error (`Msg msg, ctx) -> () ; Sdl.log "Error: %s" msg ; destroy_resources ctx ; Sdl.quit () ; exit 1 ;;
It took a bit of fiddling before finding something I was happy with, I’ll gladly take any criticism/feedback :)
If you have made a game or project with tsdl
, please do tell us about it!
(personally, I’m going through the “Nature of Code” book and want to implement the exercises in many languages/libraries)
Yotam Barnoy then said
Take a look at my Railroad Tycoon reimplementation.
OCaml.org Newsletter: April 2023
Thibaut Mattio announced
Welcome to the April 2023 edition of the OCaml.org newsletter! As with the previous update, this has been compiled by @sabine and @tmattio.
The OCaml.org newsletter provides an overview of changes on the OCaml.org website and gives you a glimpse into what has been going on behind the scenes. You can find a list of previous issues here.
Our goal is to make OCaml.org the best resource for anyone who wants to get started and be productive in OCaml. 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 prioritise our work and make progress towards our goal. Thank you!
We present the work we’ve been doing this month in three sections:
- Learn area: To make sure that we focus on the changes that truly have an impact on the success of OCaml and its community, we conducted a user survey targeted at OCaml newcomers. The survey allowed us to better understand their outlook on the existing site and their needs and wishes for the upcoming changes.
- Package documentation: Following the recent changes to the package area, we’ve continued to make improvements to the usability of the package overview and documentation pages.
- General Improvements: We also worked on general maintenance and improvements, and we’ll highlight some of them.
Learn Area
- 1. User Survey
This month, we published the survey that we started preparing in March. The survey was promoted on various platforms, including the official OCaml Discuss platform, Discord, LinkedIn, Twitter, and received a lot of engagement: in total, we got 57 responses before we had to close the survey in order to analyze the results adequately.
Apart from this, we reviewed recordings of the previous round of user interviews we did on the Learn and Package areas, to group and prioritise the user feedback for use in upcoming user interviews. We also provided a public summary of the survey results on the OCaml Discuss.
Overall, we’re now in a very good position to understand which changes should be made to the Learn area in order to improve the learning experience on OCaml.org. Our work will continue in May with the first wireframes for the new Learn area.
- 2. Work-in-progress Improvements on Documentation Pages
In addition to the high-level overhaul of the Learn area we’re working on, outlined above, we also made several smaller improvements on the documentation to continuously improve the content of the documentation.
Many of the outstanding pull requests on ocaml/ocaml.org contain updates to the existing documentation pages of the Learn area. We aim to merge the majority of these in May.
We are incredibly thankful for your feedback, suggestions, and help along the way. We are striving to make learning OCaml frictionless by providing high-quality content on OCaml.org. It’s quite a big task, and everyone’s help is essential to allow us to make this happen.
Package Documentation
Following the recent changes in the package area, we continued to make improvements to the layout. Notably, we added a small footer to the Learn and Package sections, which solves the issue of sticky-positioned sidebars moving out of the screen when scrolling into the footer. To better highlight the currently active section when scrolling through the document, we reworked the table of contents UI in both the Package and Learn sections.
We now collapse the reverse dependencies section on the package overview page when it has more than 100 entries. To make room for upcoming package status badges, we moved the breadcrumbs in the package area above the main content area in line with the Figma designs. We also updated the styles of the package search results page to be more compact, collapsing author lists with more than five items, styling package tags the same as on the package overview page, and we added a link to go directly to the package documentation.
Relevant PRs/Issues:
- The Learn section and the Package section now have a small footer attached to the bottom of the screen (ocaml/ocaml.org#1018). This resolves the UX issue where the sticky-positioned sidebars would move upwards out of the screen when scrolling into the footer. An alternative solution where the sidebars shrink as the footer comes into view has been explored but ultimately discarded due to higher complexity and maintenance needs.
- The table of contents UI in the Package section as well as in the Learn section is reworked to highlight the currently active section when scrolling through the document (ocaml/ocaml.org#1094). This makes it easier to see progress in reading the content and easier to relate to where we are in a larger document.
- The layout of the package documentation section is now wide (ocaml/ocaml.org#1097), with an increased gap on the
xl
screen size. - Since there can be hundreds or even thousands of reverse dependencies for a package, we’re now collapsing the reverse dependencies section when there are more than 100 items (ocaml/ocaml.org#1101).
- The breadcrumbs in the package area are now above the main content area (ocaml/ocaml.org#1133) with the intent to make room next to the package name for upcoming badges that, e.g., provide information on the build status.
- We updated the styles of the package search results page to be more compact (ocaml/ocaml.org#1134): (a) author lists with more than five items are collapsed by listing the first five authors and “et al.”, (b) package tags are now styled the same as on the package overview page, (c) a link to go directly to the package documentation is provided.
- Work in Progress: Basic In-Package Search
During the last month, we made progress on bringing basic in-package search functionality to the OCaml.org package documentation. Work on a prototype is ongoing on staging.ocaml.org (see this Discuss post), and we plan to roll out a rudimentary version of in-package search in May.
We’ll be rolling out the initial version as experimental, so it may have some issues and will be quite limited. We are releasing this early, as we find that having in-package search is vital for the usability of the package documentation. The upside of this process is that we’re able to adapt to your feedback and ideas as we design the final product later on.
General Improvements
We made improvements to the OCaml.org dashboard and GitHub actions workflows. The dashboard now displays the Git commit hash and memory consumption in bytes. We worked on fixing the RSS feed scraping workflow, which resulted in the ability to trigger the scraper to run via the GitHub UI and the ability to run workflows on a local machine. The scraping workflow was made more robust against the temporary unavailability of sources, and individual feeds for the Blog page are now scraped separately and merged into a global feed.
We are currently working on exposing the build status data for packages on the package overview pages. We also started to work on a dedicated “Install” page for OCaml with the help of the OCaml community. The new page will provide shorter instructions on how to set up OCaml quickly and the corresponding patch includes an overall revision of the “Get Up and Running” documentation.
In addition to all of this, the team has diligently tackled numerous bug fixes and quality-of-life improvements to enhance the overall user experience.
Relevant PRs/Issues:
- We improved the ocaml.org dashboard to display the Git commit hash from which the currently running instance has been built (ocaml/ocaml.org#1136), and to display the memory consumption in bytes (ocaml/ocaml.org#1060). For this, the build needed to happen in a Git-enabled folder which required enabling the “include Git” option on the deployment pipeline (ocurrent/ocurrent-deployer#184).
- RSS feed scraping (which provides the data we display on the “Blog” page) broke in January when Git LFS was introduced to store the OCaml Playground assets. Another issue we observed was that HTTP requests to some sources would time out (kayceesrk/river#8). We worked on fixing the scraping workflow and ultimately succeeded. As a consequence of this work, we now enjoy improvements to the GitHub actions workflows, such as the ability to trigger the scraper to run via the GitHub UI, and the ability to run workflows on a local machine (ocaml/ocaml.org#1068). Subsequently, the scraping workflow was made more robust against temporary unavailability of sources (ocaml/ocaml.org#1120), and, instead of building a global feed by scraping all sources at the same time, individual feeds are now scraped separately and merged into a global feed (ocaml/ocaml.org#1144).
- We are working on exposing the build status data for packages on the package overview pages (ocaml/ocaml.org#977). As part of this effort, check.ocamllabs.io has already been moved to check.ci.ocaml.org (ocaml/infrastructure#40) by the infrastructure team.
- To provide better statistics on the programming languages used in the ocaml/ocaml.org repository, we now exclude vendored files from stats (ocaml/ocaml.org#1074).
- Some AlpineJS-related bugfixes and cleanups on the search dropdown (ocaml/ocaml.org#1069) and sidebar (ocaml/ocaml.org#1061).
- Upgrade AlpineJS to 3.12.0, HTMX to 1.9.0 (resolves ocaml/ocaml.org#877).
- We started working on an “Install” page for OCaml with the help of the OCaml community at https://discuss.ocaml.org/t/please-improve-my-draft-of-an-install-page-on-ocaml-org/11837. The intent of this page is to provide short instructions on how to set up OCaml quickly by leveraging OS detection via JavaScript. The upcoming patch includes an overall revision of the “Get Up and Running” documentation to provide better section headings and to clarify instructions while removing noise from the document.
- In response to an inquiry about package documentation failing to build, the CI team helped us by investigating why the solver fails for the package in question. It turns out that, currently, the solver appears to only use two OCaml versions: 4.14 and 5.0.0. Until this changes, any package that does not work with either of these OCaml versions will not have its package documentation built successfully.
- A new page that highlights all the previous Outreachy internships conducted by the OCaml community (ocaml/ocaml.org#1009) has been added to the Community section.
- We improved the HACKING.md documentation to mention prerequisites on the development environment and to link to the Docker images built by the CI which are stored on Docker Hub (ocaml/ocaml.org#1102). The intent of this is to make it simpler for new contributors to join the project.
- Rearranged the “featured” section on the Blog page to allow featuring less than three posts (ocaml/ocaml.org#1082).
- Bugfix for a Unicode rendering problem (ocaml/ocaml.org#1083) when searching for the empty string on the package search results page.
- Added ’Roboto Mono’ as a dedicated monospace font (ocaml/ocaml.org#1085) to achieve a consistent display of code sections for all users.
- Errors in the documentation were reported by OCaml users. Thank you! We fixed them immediately: (1) Resolve unused for-loop index i Error
ocaml/ocaml.org#1084, (2) remove incorrect mention of utop
ocaml/ocaml.org#1086, and (3) Explain how to activate -dtypedtree in
utop-full
ocaml/ocaml.org#1089 - We vendored an experimental YAML parsing tool
tmattio/yoshi into the ocaml.org repository to explore if that is a suitable way to simplify the YAML parsing aspect of the current
ood-gen
tool of ocaml.org. - The package autocomplete search input in the top navigation bar now reacts faster since the throttling delay has been removed (ocaml/ocaml.org#1122).
- We made the share button of the OCaml Playground more obvious (ocaml/ocaml.org#1117) by adding a caption.
- We worked on the experimental changelog page.
- Considering that there are some unmet caching needs in our web stack (e.g., in the package documentation section: looking at the many HTTP requests and rendering the module tree menu), we reached out to the OCaml community to understand what the ecosystem is like at the moment and if there is a meaningful opportunity to contribute to the OCaml ecosystem as part of our work on OCaml.org.
- There is an open PR for adding WIP dev-container that can make it easier to get started developing on the ocaml/ocaml.org repository.
- The “Contribute” link on the documentation pages now links to the commit from which the content was rendered (ocaml/ocaml.org#1139
- The OCaml.org project
officially adopted the OCaml Code of Conduct by adding
CODE_OF_CONDUCT.md
to its GitHub repository (ocaml/ocaml.org#1135) and by adding ocaml/ocaml.org to the list of adopters (ocaml/code-of-conduct#6) - The problems in the exercises section of the Learn area can now be filtered by difficulty (ocaml/ocaml.org#1141).
- Bugfix: the problem difficulty symbols in the exercise section would be cut off in the too-small margins. Now the
problem difficulty symbols in the exercises section only show up in the margin on
xl
screen size (ocaml/ocaml.org#1138).
A bestiary of GADT examples?
Continuing this thread from last week, Reuben Rowe said
I have used GADTs in rotor to implement a rich identifier type for different syntactic elements of the OCaml language, as well as some custom zipper types over the OCaml compiler typed AST.
2023 StackOverflow Developer Survey
Thomas Gazagnaire announced
This year, OCaml is on the list of languages (while it wasn’t in 2021!).
So now we can tell the world that we everyone is using (and hopefully want to continue to use) OCaml: https://stackoverflow.blog/2023/05/08/the-2023-developer-survey-is-now-live/ :camel:
Release 0.5.4 of Fmlib_browser
Helmut announced
It is a pleasure to announce the release 0.5.4 of Fmlib_browser
. The library helps to write interactive webapplications running in the browser. It is quite easy to write interactive webapplications with the help of this library. The user code
is purely descriptive (aka functional) which avoids many common errors.
You can find some simple examples here and in the overview.
Install the library with
opam install fmlib_browser
The new release 0.5.4 fixes some bugs in the initial version 0.5.3 and has some minor added functionality.
OCaml Platform Newsletter: April 2023
Thibaut Mattio announced
Welcome to the first issue of the OCaml Platform newsletter!
Following in the footsteps of the OCaml.org newsletter and inspired by the Multicore and Compiler newsletters, we’re excited to bring you monthly updates on the progress we’re making in improving the OCaml Developer Experience.
The OCaml Platform is the recommended set of tools to work and be productive with OCaml. The Platform tools fill gaps in the OCaml developer experience and allow developers to perform specific workflows (e.g. building packages, formatting code, generating documentation, releasing packages, etc.).
At the end of the day, all the work we’re doing on the OCaml Platform has one objective: improving the OCaml developer experience, so in this newsletter, we’ll present the progress we’re making on the different projects from the lens of these developer workflows. Based on the results of the OCaml surveys (2020 and 2022), discussions with industrial users, continuous community feedback on Discuss, and other sources of user input, here are the workflows we’re currently working on:
- Building Packages: Our immediate goal for the build workflow is to remove the friction associated to using two different tools for package management and build system. To this end, we plan on integrating opam capabilities directly into Dune, establishing it as the singular tool needed to build OCaml projects. As a by-product of this integration, we aim to improve other workflows such as working on multiple projects, cross-compilation, and improving the overall experience to get started with OCaml.
- Compiling to JavaScript: We’re continuously supporting tools to compile OCaml to JavaScript. Dune integrates well with Js_of_ocaml and we’ve been working on an integration of Dune and Melange, a recent fork of ReScript that aims to bring to integrate closely with the OCaml ecosystem.
- Generating Documentation: The state of the OCaml Packages documentation is reported as a major pain point in the OCaml surveys (2020 and 2022). We’re working towards empowering OCaml developers to create high-quality documentation for their packages. Now that the documentation of packages is readily available on OCaml.org, we want to make writing documentation rewarding and straightforward. We’re working towards making Odoc suitable to create manuals by adding new features, improving the navigation, and expanding the odoc markup syntax to support rich content such as tables, images and graphs.
- Editing and Refactoring Code: We aim to enrich the OCaml editor support with more workflows to improve code navigation and automate refactoring. Our main focus currently is on adding support for project-wide references to Merlin. Future work will include implementing a project-wide rename query and queries such as renaming arguments. We are also working towards bringing the editor support for OCaml to the web and third-party platforms such as OCaml Playground, ReplIt, and GitHub Codespaces.
- Formatting Code: Our goal for formatting code is focused on improving accuracy, particularly for the to comments. We also want to strike the right balance between providing a default profile that appeals to most users and not requiring configuration to format your OCaml projects, while still maintaining a fully configurable formatter. Additionally, we plan to enhance the backward compatibility of ocamlformat and better integrate Dune and ocamlformat.
I’ll also take the opportunity to call for new contributors. Platform projects are always looking for new maintainers and contributors, so if you’re interested in the future of OCaml’s developer experience and would like to shape that future with us, please reach out to me or any Platform maintainers. If you’re an industrial user looking for support on the OCaml Platform and would like to fund the maintainers and the developments on the Platform tools, also don’t hesitate to [reach out to me](mailto:thibaut@tarides.com).
April has seen a flurry of activity, and we can’t wait to share our progress with you. So let’s get right to it!
In this inaugural issue, we’ll be discussing progress on the following projects:
- Building Packages
- [Dune] Exploring Package Management in Dune
- [opam] Native Support for Windows in opam 2.2
- [Dune] Improving Dune’s Documentation
- [Dune] Composing installed Coq theories
- [Dune] Dune Terminal User Interface
- [Dune] Running Actions Concurrently
- [Dune] Benchmarking Dune on Large Code Bases
- Compiling to JavaScript
- [Dune] Compile to JavaScript with Melange in Dune
- Generating Documentation
- [Odoc] Add Search Capabilities to
odoc
- [Dune] User-Friendly Command to Generate Documentation
- [Odoc] Support for Tables in
odoc
- [Odoc] Add Search Capabilities to
- Editing and Refactoring Code
- [Merlin] Support for Project-Wide References in Merlin
- [Merlin] Improving Merlin’s Performance
- [OCaml LSP] Using Dune RPC on Windows
- [OCaml LSP] Upstreaming OCaml LSP’s Fork of Merlin
- Formatting Code
- [OCamlFormat] Migrate OCamlFormat from an AST to a CST
- [OCamlFormat] Closing the Gap Between OCamlFormat and
ocp-indent
Releases
Here are the new versions of Platform tools we released in April. Have a look at the OCaml Changelog to read announcements and feature highlights!
Building Packages
- [Dune] Exploring Package Management in Dune
Contributors: @rgrinberg (Tarides), @Leonidas-from-XIV (Tarides), @gridbugs (Tarides), @kit-ty-kate (Tarides)
Earlier this month, we announced that we’ve started exploring package management in Dune. You can read the Request for Comment (RFC) that details our work-in-progress plans for the feature on GitHub.
We’re currently focused on building prototypes for different parts of the Dune workflow: source fetching, building non-Dune opam packages, and generating a lock file.
In April, we merged a first version of Source Fetching. We also started thinking about how Dune could build opam packages and merged a PR laying the foundation for the rules on building them in Dune.
Activities:
- Completed and merged a first version of Source Fetching
- Upstreamed a patch in opam to remove preprocessing of backwards-compatibility code. This helped to reduce the number of dependencies to vendor in Dune when vendoring opam.
- We merged a PR that lays the foundation and provides a skeleton for the features related to building opam packages.
- Following work on
0install-solver, which we’ll use as a solver in Dune 4, we open a PR on
ocaml/opam-repository
to remove constraints on package versions in conflicts and a patch on opam for the same conflict.
- [opam] Native Support for Windows in opam 2.2
Contributors: @rjbou (OCamlPro), @kit-ty-kate (Tarides), @dra27 (Tarides), @emillon (Tarides), @Leonidas-from-XIV (Tarides)
Bringing Tier-1 support for Windows has been a dream for some time and April has seen us get closer than ever before to the first alpha of opam 2.2, which we expect in May. This early alpha is a big step towards the release of opam 2.2 with native Windows support, and is the result of a humongous amount of effort bringing together the work of many people done over the years.
Activities:
- Configure: Ensure a complementary (32bit on 64bit platforms and 64bit on 32bit platforms) C compiler is installed on Windows ocaml/opam#5522
- Do not silently disable MCCS if a C++ compiler is not present ocaml/opam#5527
- Move the
.ocamlinit
script out of the root directory ocaml/opam#5526 - MCCS on Windows does not respect avoid-version ocaml/opam#5523
- Setup benchmarking using current-bench ocaml/opam#5525
- Update to latest
msvs-detect
ocaml/opam#5514 - Fix the compilation of
camlheader
when BINDIR contains escaping characters ocaml/opam#12214 - doc: ? evaluates to true if defined ocaml/opam#5512
- Stop the configure script from downloading and vendoring dependencies ocaml/opam#5511
- Remove preprocessing of backwards-compatibility code ocaml/opam#5508
- Fix linting on
opam-crowbar.opam
ocaml/opam#5507 - depexts: reword message ocaml/opam#5499
- Replace usage of CPPO ocaml/opam#5498
- Check for the presence of swhid_core in the configure script ocaml/opam#5497
- Add package stanza on all rules that depend on
opamMain.exe.exe
ocaml/opam#5496
- [Dune] Improving Dune’s Documentation
Contributors: @emillon (Tarides)
In March, we started restructuring the Dune documentation according to the Diataxis framework. We opened a draft PR to demonstrate the overall target structure. The new structure will improve the usability of the documentation, allowing users to find the information that they are looking for, as well as enable us to better identify gaps that need to be addressed.
In April we’ve continued this work, filling in some of those gaps as well as rewriting documents to better fit in the intended quadrant of the framework.
Activities:
- Turn “Automatic Formatting” into a how-to ocaml/dune#7479
- Move lexical conventions to reference ocaml/dune#7499
- Turn
opam.rst
into 3 guides ocaml/dune#7515 - Add some info about writing docs ocaml/dune#7537
- Merge
classical-ppx
intopreprocessing-spec
ocaml/dune#7538 - Merge reference info about findlib ocaml/dune#7567
- Add a lexer for opam files ocaml/dune#7574
- [Dune] Composing installed Coq theories
Contributors: @Alizter and @ejgallego (IRIF)
We’ve merged the PR that brings support for composing Coq theories with Dune!
This was a huge effort lead by Ali Caglayan and Emilio Jesús Gallego Arias that started earlier this year. Starting in Dune 3.8, Coq users will be able to use Dune even if they depend on Coq projects that use other build systems (such as make).
Activities:
- Merged the PR that adds support for composition with installed theories to the Coq rules
- [Dune] Dune Terminal User Interface
Contributors: @Alizter, @rgrinberg (Tarides)
We’re working on a new Terminal User Interface (TUI) mode for Dune. Our goal is to give Dune users an interactive GUI-like experience right from the terminal, making it easier to interact with build targets, observe processes, and more. The work is still very much in progress, but expect gradual improvements of
dune build --display tui
in the coming months.Activities:
- Introduced the new
tui
mode for Dune. - Enabled Dune to redisplay 24-bit color output.
- Introduced the new
- [Dune] Running Actions Concurrently
Contributors: @Alizter and @hhugo (Nomadic Labs)
In January, we began working on allowing Dune to execute actions and run inline tests concurrently. This month, we merged the two PRs and the feature will be available in the upcoming Dune 3.8. We’re especially excited about the ability to run inline tests concurrently to speed up test cycles!
Activities:
- We’ve merged the PR that implements a new concurrent action in Dune, which allows you to execute actions concurrently.
- We also merged the PR that built on this feature to enabled Dune to run inline tests concurrently.
- We’ve patched
ppx_inline_test
to leverage the new feature.
- [Dune] Benchmarking Dune on Large Code Bases
Contributors: @gridbugs (Tarides), @Leonidas-from-XIV (Tarides)
In March we added continous benchmarking of Dune builds on a 48 core baremetal system. This is the result of a lot of work that included building a big monorepo for opam packages allowing users to run Dune benchmarks on large code bases.
In April we added support for benchmarking builds in watch mode as well. This allows us to monitor for regressions as we move forward with major initiatives, such as package management.
Activities:
- Add watch-mode benchmarks of dune monorepo using Dune’s streaming RPC interface
Compiling to JavaScript
- [Dune] Compile to JavaScript with Melange in Dune
Contributors: @anmonteiro, @jchavarri (Ahrefs), @rgrinberg (Tarides)
You may have read that Ahrefs migrated its codebase from ReScript to Melange, a new OCaml-to-JavaScript compiler based on ReScript.
The goal of Melange is to offer an alternative to ReScript that pairs well with the OCaml ecosystem. To that end, Antonio Nuno Monteiro and Javier Chávarri have been working on integrating Melange and Dune, allowing it to easily compile OCaml projects to JavaScript with Melange.
The feature will be available in the upcoming Dune 3.8. You can already read the documentation in Dune’s manual to get a glimpse of how the feature will work. You can also have a look at the opam Melange template built by the Melange team.
Activities
- Write a manual page in Dune to compile to JavaScript using Melange.
- Make Melange work on 4.13-5.1 rather than just 4.14
- In addition to what we did in April, here are some noteworthy PRs that were worked on in previous months:
- Added a new field
melange.runtime_deps
to libraries, so that Melange library authors can tell Dune which frontend assets (like CSS or image files, fonts etc) have to be installed with their library - Speed up rule generation for librariess and executables. This was useful for Melange, but benefits every Dune project.
- Make reactjs-jsx-ppx a standalone ppx
- Implemented a
module_system
field for the melange stanza (e.g.(module_systems (es6 mjs) (commonjs js) (commonjs cjs))
which allows to output multiple module systems / js extensions at the same time to the melange output folder
- Added a new field
Generating Documentation
- [Odoc] Add Search Capabilities to
odoc
Contributors: @panglesd (Tarides), @EmileTrotignon (Tarides)
We’re working on generating a search index and adding a search bar to
odoc
-generated documentation. We’re still exploring the different approaches and we are working with the OCaml.org team to implement a search bar on the OCaml packages documentation.Activities:
- We started prototyping the search index and search bar and we’re discussing the design of it. In particular, we’ve used the compiler Shapes in the prototype and we’ll explore using odoc’s path resolver instead as a next step.
- [Dune] User-Friendly Command to Generate Documentation
Contributor: @EmileTrotignon (Tarides), @jonludlam (Tarides)
We’re working towards making generating documentation in Dune more accessible, especially for newcomers. Currently, the
dune build @doc
command generates documentation in the_build
directory, and users simply have to know that they need toopen _build/default/_doc/_html/index.html
. To work around this, we’re working on a newdune ocaml doc
command to generate documentation and open it in the browser directly.Activities:
- We opened a PR that implements the
dune ocaml doc
command in March. This month, we tested the feature on macOS. We are now working towards completing the Windows tests.
- We opened a PR that implements the
- [Odoc] Support for Tables in
odoc
Contributors: @gpetiot (Tarides), @panglesd (Tarides), @Julow (Tarides), @jonludlam (Tarides)
Currently, the only way to create tables with odoc is to inline HTML code in the documentation. Tis is not ideal as the HTML table syntax is not well-suited as documentation markup and the tables can only be rendered by the HTML renderer (so tables are not available in LaTex and manpages). We’re working towards a new special syntax in odoc for creating tables that is easier to use and can be rendered by all renderers.
The syntax support has been merged in odoc-parser. It provides a heavy-syntax, and a ligh-syntax inspired by Markdown:
{t a | b | c | d ---|:--|--:|:-: a | b | c | d }
The support for the feature in odoc isn’t merged yet, but should be available in the next odoc version!
Activities
- No new activity in March, but here are Pull Requests we have been working on until now:
- Add a new syntax for tables in odoc-parser (odoc-parser#11)
- Fix light table parsing (odoc-parser#14)
- Add support for tables to odoc (odoc#893)
- No new activity in March, but here are Pull Requests we have been working on until now:
Editing and Refactoring Code
- [Merlin] Support for Project-Wide References in Merlin
Contributors: @voodoos (Tarides)
Our work on Merlin focuses on the long-standing project to add project-wide occurrences support to Merlin. In April, we continued to work on the compiler patches that allow to generate the index from the compiler, and we updated the Merlin patches to work with the compiler patches, simplifying the Merlin logic that can now rely on the compiler.
The feature requires patches for the OCaml compiler, Dune, and Merlin that are still unreleased, but if you’re courageous, you can give it a try by following the documentation on
voodoos/merlin-occurrences-switch
.Activities
- We backported the compiler-side-indexation to 4.14. We performed benchmarks to evaluate the impact on build time and the size of the installed ~cmt~s. We posted the results on the PR, for both the build time and cmts size.
- We also reworked the iterator performing indexation and added most of the missing cases to the indexer. However, some elements remain unindexed due to constraints with the
Typedtree
. - We updated the “indexing” external tool following partial indexation implementation in the compiler.
- We also ported new compiler changes to Merlin on the OCaml 5.1 preview, which will allow us to work on project-wide occurrences support.
- Finally, we started refactoring and simplifying the Merlin patches to query the index now that more work is done by the compiler.
- [Merlin] Improving Merlin’s Performance
Contributed by: @pitag-ha (Tarides)
Following reports that Merlin performance scaled poorly in large code bases, we had been working on Merl-an, a tool to measure the performance of different Merlin requests.
In March, we were able to use it to identify the major performance bottlenecks, the biggest one being the PPX phase. We implemented a caching strategy for PPX and continued to work on it throughout April.
Activities:
- We worked on fixing the PPX cache and explored mechanisms to toggle the PPX phase cache. We ended up implementing a flag-based approach.
- We added six tests that cover default behavior, cache hits, cache invalidation of three kinds, and behavior in case of PPX dependencies.
- [OCaml LSP] Using Dune RPC on Windows
Contributors: @nojb (LexiFi)
In February, we released Dune 3.7.0 with support for watch mode on Windows. Building on this work, this month we fixed a couple of issues in Dune and OCaml LSP to allow OCaml LSP to use Dune RPC. This allows VSCode users to leverage Dune RPC and get build statuses and more exhaustive build errors in the editor when Dune is running in watch mode. The fixes are not released yet, but they will be available on the upcoming releases of Dune and OCaml LSP.
Activities:
- We made a patch in Dune to use the RPC protocol on Windows.
- We fixed a bug in OCaml-LSP to enable the communication with Dune RPC on Windows.
- [OCaml LSP] Upstreaming OCaml LSP’s Fork of Merlin
Contributors: @voodoos (Tarides), @3Rafal (Tarides)
We’re at the finish line of our efforts to close the gap between Merlin and OCaml LSP by upstreaming OCaml LSP’s fork of Merlin! This month, we continued on the Merlin PR that adds a hook to OCaml LSP letting it run system commands. We also opened a PR on
ocaml-lsp
to use the above patch and remove Merlin’s fork entirely. We’re expecting to release a version of OCaml LSP that uses Merlin as a library very soon.Activities:
- We discussed and reviewed changes that let you configure the process spawn for PPXs when using Merlin as a library. This led us to implement ideas concerning the exposed hook for PPX process spawning. Subsequently, we documented the complexities of splitting a PPX command between program and arguments.
- We opened a PR on
ocaml-lsp
to remove Merlin’s fork and use Merlin as a library.
Formatting Code
- [OCamlFormat] Migrate OCamlFormat from an AST to a CST
Contributors: @gpetiot (Tarides), @EmileTrotignon (Tarides)
Back in 2022, @trefis built a prototype of a new OCaml formatter that uses a Conrete Syntax Tree (CST) instead of an Abstract Syntax Tree (AST). This mode retains more information and results in more accurate formatting in a lot of cases, most especially when formatting comments which is a big pain point with OCamlFormat.
Since then, we’ve worked on migrating OCamlFormat’s syntax tree to this CST. We chose not to migrate everything at once to minimize the impact on users as much as possible, making sure that we make formatting changes only when they are bug fixes or clear improvements.
You can track our progress in this PR, which shows a diff of the current syntax tree and the target CST.
Activities:
- We made progress on the work-in-progress PR to preserve comments attached to labelled args, fixing more regressions.
- We implemented a change to keep literal char value during parsing.
- We worked on preserving the functor concrete syntax in the Parsetree.
- We normalized functions in the parser.
- [OCamlFormat] Closing the Gap Between OCamlFormat and
ocp-indent
Contributors: @gpetiot (Tarides), @EmileTrotignon (Tarides), @Julow (Tarides)
The OCamlFormat team has been working with the Jane Street teams to migrate Jane Street’s code base from ocp-indent to OCamlFormat. As a result, we’ve made tons of changes to the
janestreet
profile in recent months. Perhaps most notably, this work has allowed us to identify issues that were not specific to thejanestreet
profile, and consequently we’ve been fixing bugs and implementing formatting improvements across the board.We’re nearing the end of this project, but April has seen a lot of bug fixes and improvements that we detail below.
Activities:
- We adjusted the indentation for several language features, including extensions, class-expr function bodies, and module-expr extensions.
- We fixed issues with ocp-indent compatibility and Let vs LetIn detection after ’struct’.
- We improved the formatting of module arguments and worked on preserving comments attached to labelled args.
- We fixed issues causing changes to the AST due to strings in code blocks and comments.
- We improved the formatting of cinaps comments with strings and worked on parsing and normalizing cinaps comments.
- We made adjustments to the handling of certain language constructs, such as
protecting match after
fun _ : _ ->
and consistently wrapping (::). - We extended our test suite with numstat and a single run of ocp-indent.
Eio Developer Meetings
Sudha Parimala announced
Hi all! We’ve started having Eio developer meetings online, once every two weeks. The meeting is open to everyone. Those interested to follow Eio’s developments are welcome to join.
Agenda
The meetings are for planning the development of Eio. The current status and plans for Eio 1.0 are being tracked at Eio#388.
We’re also eager to hear feedback on Eio from users, and their experience of migrating applications to Eio. This will greatly help us to make the experience more pleasant and close gaps, if any. If you’re looking to get started, the README is a good place to start.
Timings
The meeting takes place on alternate Mondays, at 10:00 UK.
- Next meeting: June 5, Monday
- Time: 10:00 AM - 11:00 AM BST (9:00 AM - 10:00 AM UTC)
- Link to meeting: meet.google.com/byo-dfiz-dou
- Meeting notes: https://docs.google.com/document/d/1ZBfbjAkvEkv9ldumpZV5VXrEc_HpPeYjHPW_TiwJe4Q/
- Use this calendar link to add it to your calendar - Eio Developer Meetings
New major release of Parany (v14.0.0)
UnixJunkie announced
# opam search parany [...] parany 14.0.0 Parallelize any computation
I switched back the runtime to fork+marshal. As was the case before version 13.0.0. Versions 13.* (up to 14.0.0 excluded) use ocaml5-threads to parallelize computations.
https://github.com/UnixJunkie/parany
There is a branch https://github.com/UnixJunkie/parany/tree/ocaml5_threads if anybody wants to maintain this backend.
The Parany.Parmap module has new functions for arrays: https://github.com/UnixJunkie/parany/blob/master/src/parany.mli
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.