-
Notifications
You must be signed in to change notification settings - Fork 84
Introduce let@ binding operator
#1891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in | ||
| invariant man st exp tv |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: semgrep.let-unit-in Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, looks like semgrep isn't particularly smart (again) and thinks let@ is just let...
| let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in | ||
| Idx.add bytes_offset remaining_offset |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: semgrep.let-unit-in Warning
| let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in | ||
| Idx.mul item_size_in_bytes x |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: semgrep.let-unit-in Warning
| let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in | ||
| Idx.add bytes_offset remaining_offset |
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: semgrep.let-unit-in Warning
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: semgrep.let-unit-in Warning
|
I find the |
|
I've always found the f (fun x ->
e
)Note that there's a level of indentation coming from it just being in the function argument of f @@ fun x ->
ewhich tries to give the impression of linear code as opposed to going down into a scope (which it does). And that's exactly the kind of code let binding operators were introduced for and have it just as let@ x = f in
e(Here the This offers a very easy way to avoid file descriptor leaks. Instead of the buggy let f = open "foo.txt" in
ejust do let@ f = with_open "foo.txt" in
eNo need to touch/reindent People have complained about such operator elsewhere as well (ocaml/ocaml#9887), but not for this reason at all. There nobody is advocating for the middle |
I will have to look it up, when I encounter it, but this is more due to my Ocaml illiteracy - same is the case for lots of other operators that I do not encounter on a daily base. It it helps to contain the file handle leak in an elegant way, then why not. |
As we already have the |
|
I have no preference here, so I will just join the majority. |
I'll have to see about the semgrep false positives before we can really do this anyway. Having a semgrep rule to suggest |
|
Alright, if everyone else is on board, let's do it! |
This is on top of #1880.
Instead of writing
(which is a bit odd indentaiton-wise), this provides a neat way to write it more idiomatically as
This particularly makes sense for various
Fun.protectderivatives, like the file operations introduced in #1880 to not forget closing the file (even in the case of exceptions).Such an operator already exists, e.g. in the containers library.
TODO