Use let-binding with functions whose last argument is a closure
  • Dune 43.1%
  • OCaml 34.1%
  • Makefile 22.8%
Find a file
2026-03-17 07:36:03 +01:00
.github Disable coverage report 2025-10-17 14:45:24 +02:00
.vscode Init 2024-05-13 12:22:31 +02:00
src Configure ppx_js_style to allow let operators 2025-07-29 09:04:18 +02:00
test Upgrade ocamlformat to 0.27.0 2024-12-03 19:16:23 +01:00
.gitattributes Init 2024-05-13 12:22:31 +02:00
.gitignore Init 2024-05-13 12:22:31 +02:00
.ocamlformat Add ocaml-version to ocamlformat config according to the project lower bound 2025-01-10 10:56:23 +01:00
CHANGES.md Split tests 2024-08-23 17:55:30 +02:00
dune Init 2024-05-13 12:22:31 +02:00
dune-project Update dependencies 2025-06-06 09:24:44 +02:00
letfun-tests.opam Update dependencies 2025-06-06 09:24:44 +02:00
letfun.opam Require dune.3.17 2024-12-16 10:35:11 +01:00
LICENSE Init 2024-05-13 12:22:31 +02:00
Makefile Configure with-dev-setup dependencies and attach to test package 2024-09-08 18:57:22 +02:00
README.md Archive notice 2026-03-17 07:36:03 +01:00

letfun

⚠️ This repository is now a public archive. I am no longer maintaining it.

This was a let-fun experiment! I've come across a few other projects with similar constructs. I may incorporate a similar operator in other projects, and I'll keep an eye on OCaml's stdlib for related developments.

Happy let-binding!


letfun is a tiny library which allows you to use a let-binding style to handle functions applications that expect their last argument to be a closure. It uses for this the let& operator.

For example:

let print_hello_world file =
  Out_channel.with_open_text file (fun oc ->
    Out_channel.output_string oc "Hello, ";
    Out_channel.output_string oc "World\n")

Can be rewritten as:

let print_hello_world file =
  let open Letfun in
  let& oc = Out_channel.with_open_text file in
  Out_channel.output_string oc "Hello, ";
  Out_channel.output_string oc "World\n"

Note that many projects use the @@ operator in certain situations:

let print_hello_world file =
  Out_channel.with_open_text file
  @@ fun oc ->
  Out_channel.output_string oc "Hello, ";
  Out_channel.output_string oc "World\n"

⚠️ This library is highly experimental, do not use!