OCaml Weekly News

Previous Week Up Next Week

Hello

Here is the latest OCaml Weekly News, for the week of July 23 to 30, 2024.

Table of Contents

.mlx syntax dialect

Andrey Popp announced

Dear OCaml community,

it is my pleasure to announce a release of .mlx dialect.

The .mlx dialect extends OCaml syntax with JSX expression construct, following the example of JSX in JavaScript/ReasonML. A brief snippet:

let page ?(encoding="utf8") ~title ~content =
  <html>
    <head>
      <meta charset=encoding />
      <title>title</title>
    </head>
    <body>
      content
    </body>
  </html>

let _ = <page title="Hello" content="World" />

The main use case is to make it easier to describe user interfaces with OCaml, which can range from generating HTML (example with Dream) or describing interactive UIs with ReasonReact (example).

Installation and usage

Install the packages from opam:

opam install mlx ocamlmerlin-mlx

Then configure dune to use the mlx preprocessor:

(dialect
 (name mlx)
 (implementation
  (extension mlx)
  (merlin_reader mlx)
  (preprocess
   (run mlx-pp %{input-file}))))

Now files with .mlx extension will be treated as OCaml modules.

The merlin/ocamllsp users will get roughly the same level of support for .mlx syntax as they get for .ml but some additional text editor/IDE configuration is needed to associate .mlx files with merlin/ocamllsp.

For neovim users there's a plugin ocaml-mlx/ocaml_mlx.nvim, which does that bit of a configuration and provides highlighting for .mlx files based on a tree-sitter parser.

heml, a HEEx-inspired HTML templating ppx for OCaml

Petri-Johan Last announced

I've been working on heml, a PPX extension that allows you to build complex HTML templates directly in your OCaml code.

It's a direct implementation of Elixir Phoenix's HEEx templates.

The README on GitHub has an example video of what it looks like in the editor and a bunch of example code, but here's a short snippet for convenience:

(* layouts.ml *)
let layout ~title contents = {%heml|<!DOCTYPE html>
<html lang="en">
  <head><title><%s= title %></title></head>
  <body>
    <%raw= contents %>
  </body>
</html>|}

(* main.ml *)
let heading ~text = {%heml|<h1><%s= text %></h1>|}

let greet ~user = {%heml|<p>Hello, <%s= user %></p>|}

let () =
  let title = "Hello, OCaml!" in
  print_endline {%heml|<Layouts.layout title={title}>
    <.heading text="Hello!" />

    <%= List.iter (fun user -> %>
      <.greet user={user} />
    <%= ) ["Steve"; "Becca"; "John"]; %>

</Layouts.layout>|}

heml differs from other templating solutions by allowing you to call OCaml code directly in the template, which is extremely useful for looping and conditional rendering. You can also create and call your own components/layouts.

heml leverages the OCaml LSP for accurate in-line errors, and the templates are parsed and compiled into a series of Buffer writes which returns a string at runtime.

I'm still waiting for it to be released on opam, but thought I'd share it in the meantime in case anyone would be willing to check it out and provide feedback :slight_smile: .

Forester 4.2

Jon Sterling announced

I am pleased to announce the release of Forester 4.2 on opam, which is an OCaml utility to develop “Forests”, which are densely interlinked mathematical websites / Zettelkästen similar to the Stacks project or Kerodon. You can see the changelog on my own Forest.

This release adds many new features and improvements, including:

  • First-class functions and lazy arguments, which can be used to implement more ergonomic MathML macros.
  • A new query language, which is now expressive enough to encode the backmatter
  • Improved performance of graph analysis (2x overall speedup rendering my own forest)

To see other features and documentation of breaking changes, please view the Forester 4.2 Release Notes.

My thanks to @kentookura and Jinser Kafka for their contributions to this release.

First Robotics and OCaml - Do you know any local teams?

jbeckford announced

For those who don't know, First Robotics is a competitive, international high school league for robotics: https://www.firstinspires.org/robotics/frc.

I've helped a couple students write "scouting" software partially in OCaml and partially in Java: https://github.com/diskuv/scoutapps/tree/main?tab=readme-ov-file#sonic-scout-apps

It is a very very slow season for robotics teams, but if your local high school participates now is a great time for the mentors of that team to get ready. If you know a team that needs scouting software and want to help spread OCaml to your local neighborhoods … please direct message me.

2nd editor tooling dev-meeting: 25th of July 🧙

Continuing this thread, vds announced

Thanks a lot to all participants and speakers, it was a very nice and interesting meeting !

You can find the meeting notes here: https://github.com/ocaml/merlin/wiki/Public-dev%E2%80%90meetings

With the summer (/winter) break coming for a lot of us, the next meeting will take place in September. We will implement a call-for-presentation and a poll to choose meeting times by then.

Don't hesitate to tell us right away if you would like to give a presentation or if you have subjects that you would like us to take on. (@andreypopp would you be interested in talking about melange and how it integrates with editor tooling ?)

Other OCaml News

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.