OCaml Weekly News
Hello
Here is the latest OCaml Weekly News, for the week of March 14 to 21, 2023.
Table of Contents
- Js_of_ocaml 5.1
- Petrol 1.2.0 release - Postgres Support + User-extensible types
- Docfd: TUI fuzzy document finder 0.2.3
- OCamlot - Activitypub server written in OCaml
- new versions of VS Code extensions Alcotest and Expect and Inline tests, now on Open VSX too
- Autofonce, a modern runner for GNU Autotests suites
- Release of piece_rope 0.9.0
- Old CWN
Js_of_ocaml 5.1
Hhugo announced
I’m pleased to announce the release of js_of_ocaml 5.1. It should soon be able available in opam.
Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js.
This release includes many significant changes. Here are some of the notable ones:
- Js_of_ocaml now understands most
es6
features (butimport
andexport
) - JavaScript files generated by js_of_ocaml are now UTF-8 encoded.
- Change the memory representation of OCaml strings to use JS ones. String still represent sequences of bytes and only contains codepoints in the range
[0-255]
. - Improved support for OCaml 5 effects, performing partial CPS transformation to significantly improve perfs (see http://ocsigen.org/js_of_ocaml/5.1.0/manual/performances)
- Various improvements to make the compiler faster.
- Separate compilation only link compilation units that are needed, similar to
ocamlc
, and generate much smaller js files
See the Changelog for other changes.
Petrol 1.2.0 release - Postgres Support + User-extensible types
Archive: https://discuss.ocaml.org/t/ann-petrol-1-2-0-release-postgres-support-user-extensible-types/11691/1
Kiran Gopinathan announced
I’m pleased to announce the latest release of Petrol - A high level typed SQL API for OCaml (in the process of being published to opam).
This latest release is exciting as it now adds Postgresql support (previously Petrol only supported Sqlite3).
Petrol makes using SQL from OCaml a breeze:
open Petrol open Petrol.Sqlite3 (* 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 ]
and here’s how you write queries:
(* 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
Petrol compiles down to Caqti queries under the hood, and comes with a nifty migration system built-in, so you can seamlesly update your database tables without disrupting end users:
(* declare a table with a migration for a new [age] column in version 1.2.0 *) let t, Expr.[id;age;url] = VersionedSchema.declare_table db ~name:"person" Schema.[ field ~constraints:[primary_key ~name:"bookmark_id" ()] "id" ~ty:Type.int; field "age" ~ty:Type.int; field "url" ~ty:Type.text; ] ~migrations:[v_1_2_0, [ Caqti_request.Infix.(Caqti_type.unit ->. Caqti_type.unit) {sql|ALTER TABLE person ADD COLUMN age INTEGER DEFAULT 1000|sql} ]]
This and more is explained in the documentation, along with a nifty quick-starter guide: https://gopiandcode.github.io/petrol/petrol/index.html
I’ve spent some time tuning the documentation to make it easy to pick up!
You may also want to check out the tests to see it in action: https://github.com/Gopiandcode/petrol/tree/master/test
Previous discussion: https://discuss.ocaml.org/t/ann-petrol-1-0-0-a-high-level-typed-sql-api-for-ocaml-designed-to-go-fast/11166
Docfd: TUI fuzzy document finder 0.2.3
Darren announced
I’m happy to share Docfd, an interactive TUI tool finding the text file you need quickly.
(Will submit to opam when time frees up a bit.)
Screenshots and interface
Searching left is
in the repo root
Searching [github]
in the repo root
The TUI is divided into three sections:
- Left is the list of documents which satisfy the search constraints
- Top right is the preview of the document
- Bottom right is the ranked content search result list
- Bottom bar is the search interface
Controls
Docfd operates in modes, the initial mode is NAVIGATION
mode
NAVIGATION
mode
- Scroll down the document list
j
or down arrow- Scroll down with mouse wheel when hovering above the area
- Scroll up the document list
k
or up arrow- Scroll up with mouse wheel when hovering above the area
- Scroll down the content search result list
Shift~+~j
or ~Shift~+Down arrow- Scroll down with mouse wheel when hovering above the area
- Scroll up the document list
Shift~+~k
or ~Shift~+Up arrow- Scroll up with mouse wheel when hovering above the area
- Open document
Enter
- Docfd tries to use
$VISUAL
first, if that fails then Docfd tries$EDITOR
- Docfd tries to use
- Switch to
CONTENT SEARCH
mode/
- Exit Docfd
q
orCtrl+c
CONTENT SEARCH
mode
- Content search field is active in this mode
Enter
to confirm search constraints and exit search mode
Limitations
- Docfd is focused on typical desktop use, so simplicity of components is often favoured over strict performance
- That being said, the in-memory index and search should still be performant enough
- No on-disk index is built
OCamlot - Activitypub server written in OCaml
Kiran Gopinathan announced
I’m pleased to announce the release of a project that I’ve been working on, on-and-off for a while now: an activitypub server in OCaml — OCamlot.
https://github.com/Gopiandcode/ocamlot
It’s wildly incomplete, and currently only the bare-bones minimum to be a considered an activitypub server, but it’s coming along nicely.
Currently it supports:
- profiles, custom profile pictures, about
- likes, reposts
- replies
and that’s all.
Some screenshots:
- Feed
- Writing replies:
- Listing users:
- Profile page:
- Post replies
Now, the things that this community would care about:
- The server is implemented using dream: https://github.com/Gopiandcode/ocamlot/blob/master/lib/server/server.ml
- The underlying database is Postgres (or Sqlite), accessed from OCaml using Caqti + Petrol: https://github.com/Gopiandcode/ocamlot/blob/master/lib/database/tables.ml
- Ingesting and producing activitypub entities is done using the decoders library: https://github.com/Gopiandcode/ocamlot/blob/master/lib/activitypub/types.ml
- Rendering is all done server-side using tyxml: https://github.com/Gopiandcode/ocamlot/tree/master/lib/view
Seeing as there has been some interest in this community recently about activitypub integration in OCaml, I figured this might be interesting.
I have an instance running on over at https://ocamlot.xyz – as a warning, I’ve done most of my testing locally using pleroma, so there may be some slight issues interacting with other server implementations at the moment.
Also would be happy to field any questions regarding navigating the activitypub spec as well. I plan to write up my experiences somewhere at some point in the future.
new versions of VS Code extensions Alcotest and Expect and Inline tests, now on Open VSX too
Roland Csaszar announced
I’ve just updated both VS Code testing extensions, as of now they are available at the Open VSX Registry too.
Bugfixes: The Opam environment of the project’s root is used, so the Dune executable in the sandbox of the project directory is used by default if such a sandbox exists. Otherwise the environment of the current Opam switch. If Dune does not work (a call
of dune --version
fails), an error message box is displayed.
Expect & Inline PPX
Alcotest & Inline Alcotest
Autofonce, a modern runner for GNU Autotests suites
Fabrice Le Fessant announced
I am not sure it might be helpful to the OCaml community, as we already have well integrated test frameworks, but here is a tool I wrote in OCaml to work with GNU projects:
autofonce
is a modern runner for testsuites created for the GNU Autoconf tools.
Compared to Autoconf tools, its main features are:
- improved terminal output
- automatic parallel execution
- promotion of tests results to fix tests
- extended syntax
- filtering by keywords, numbers and ranges
- execution from any project directory
A typical Autoconf test looks like:
# Start of a test, and the name that will be displayed AT_SETUP([Example test]) # can be used to select tests to run: AT_KEYWORDS([example test autofonce]) # create a file ~file~ with its content AT_DATA([file], [ content of file on multiple lines ]) # call some command, check its exit code, stdout, stderr AT_CHECK([cat file], [0], [stdout of my command], [stderr of my command]) # you can do more, ignore some results, run more tests in case of failure, etc. # end of the test AT_CLEANUP
I personally like the syntax better than the one of cram
tests, though there is some weird escaping issues with brackets (see the section in the doc).
Compatibility with Autoconf is only partial, as it uses a grammar interpretation of what should actually be
m4
macros, but it was good enough to run the full GnuCOBOL testsuite after a few fixes (that actually improved the testsuite).
The package is on Opam, but sources, documentation and static binaries are available from Github:
Release of piece_rope 0.9.0
Humza Shahid announced
I’m not sure how useful this is to others, but I published my first open source package to opam which can be used by anyone interested in it.
It is the same data structure used for editing text in VS Code [1] and AbiWord [2], with a few modifications to make it persistent and functional.
It provides some nice features on top which include:
- Serialising and deserialising the structure to a file for persistent undo/redo.
- Translating between offsets of different Unicode encodings (UTF-8, UTF-16 and UTF-32) for interaction with external systems and languages.
- There is a computationally expensive function to rebuild the structure, optimising it for memory usage and performance. (The idea was to use this in a GUI app when the user is inactive and rebuilding in that case - the core structure is fast but the perfectionist in me wanted it to be as fast and lean in memory as possible.)
There are some similar packages others may find useful like Zed which are a more battle-tested implementation of a similar-but-not-quite-the-same data structure as this is a new implementation.
Feel free to comment or open issues for any bugs you find during usage. Hopefully someone else out there will find this useful too.
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.