https://github.com/mbarbin/letfun
Use let-binding with functions whose last argument is a closure
https://github.com/mbarbin/letfun
Last synced: 4 months ago
JSON representation
Use let-binding with functions whose last argument is a closure
- Host: GitHub
- URL: https://github.com/mbarbin/letfun
- Owner: mbarbin
- License: mit
- Created: 2024-05-13T11:00:38.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-10-17T12:47:05.000Z (9 months ago)
- Last Synced: 2025-10-18T15:49:47.607Z (9 months ago)
- Language: Dune
- Homepage:
- Size: 52.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# letfun
`letfun` is a tiny library which allows you to use a let-binding style to handle functions applications that expects their last argument to be a closure. It uses for this the `let&` operator.
For example:
```ocaml
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:
```ocaml
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:
```ocaml
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"
```
:warning: This library is highly experimental, do not use!