# Ppx\_let vs. binding operators

**URL:** https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037
**Category:** Learning
**Created:** [January 1, 2021, 1:40pm UTC](https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037 "2021-01-01T13:40:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![e.r](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@e.r](https://discuss.ocaml.org/u/e.r)
#### Post date: [January 1, 2021, 1:40pm UTC](https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037/1 "2021-01-01T13:40:29Z")

</div>

It seems that there are two alternatives to have monadic `let`s: using ppx\_let, or binding operators as described in [here](https://caml.inria.fr/pub/docs/manual-ocaml/bindingops.html). Which one is recommended? Are there different usage cases for each?

I was using `Base`, in particular, the module `Result`. It has support for ppx\_let with `Result.Let_syntax` as follows:

```auto
    let open Result.Let_syntax in
    let%bind x = ... in
    ...

```

Is there something similar already built-in in `Result` for using binding operators?

---

<div class="post-metadata">

### Author: ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)
#### Post date: [January 1, 2021, 4:33pm UTC](https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037/2 "2021-01-01T16:33:05Z")

</div>

I don’t know that there’s a universal answer here.

At Jane Street, we make use of ppx\_let and don’t use OCaml’s new built-in binding operators. This is in part because we have several extensions that aren’t supported by the built-in operators yet (e.g., match%bind), and in part because there are some future improvements to our monadic libraries that we’re contemplating that would move them yet further away from what the built-in language support can do (e.g., having binding operators take location information to make it possible for various monadic and applicative libraries like Async, Incremental, and Bonsai to provide better error reporting and debugging tools).

It’s a little unclear how this will shake out longer term, but for now, ppx\_let is very much what we use.

y

---

<div class="post-metadata">

### Author: ![cvine](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@cvine](https://discuss.ocaml.org/u/cvine)
#### Post date: [January 1, 2021, 4:35pm UTC](https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037/3 "2021-01-01T16:35:40Z")

</div>

> [@e.r](#):
>
> Is there something similar already built-in in `Result` for using binding operators?

There doesn’t seem to be a let\* operator for standard library Result.t variants provided in the Result module, if that is what you were referring to, but to make your own you can just do:

`let ( let* ) = Result.bind`

I don’t use the Jane Street libraries but the transformations should all be the same, except that I have been told that with Lwt, `let%lwt` provides better debugging support for the concurrency monad than does aliasing `let*` to Lwt.bind.

---

<div class="post-metadata">

### Author: ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)
#### Post date: [January 2, 2021, 12:52am UTC](https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037/4 "2021-01-02T00:52:30Z")

</div>

Given a choice between having to use a PPX and not, I would rather not. PPXs are difficult to maintain and add complexity to the compilation pipeline.

There is an open PR adding let operators to the OCaml standard library, it just hasn’t been approved yet (probably no one got around to it).

---

<div class="post-metadata">

### Author: ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)
#### Post date: [January 2, 2021, 1:23pm UTC](https://discuss.ocaml.org/t/ppx-let-vs-binding-operators/7037/5 "2021-01-02T13:23:21Z")

</div>

> [@yawaramin](#):
>
> Given a choice between having to use a PPX and not, I would rather not. PPXs are difficult to maintain and add complexity to the compilation pipeline.

I appreciate the perspective, but PPXs provide so much utility I find the cost well justified, especially as the standard open source tooling (notably, Dune and Merlin) has made use of PPXs so much better.

The “deriving” PPXs are I think the most important ones. Writing hash functions, comparison functions, serializers, deserializers, etc, by hand, is dull, repetitive, and error prone. I find automating all of these away is well worth the costs of learning how to use the PPX ecosystem. And once you’ve bought in to, a useful-but-less-critical example like ppx\_let is a clearer win.

y
