# (\>\>) operator in Lwt?

**URL:** <https://discuss.ocaml.org/t/operator-in-lwt/296>\
**Category:** Learning\
**Tags:** lwt\
**Created:** [May 30, 2017, 2:20pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296 "2017-05-30T14:20:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard-Degenne](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/richard-degenne/32/112_2.png) [@Richard-Degenne](https://discuss.ocaml.org/u/Richard-Degenne)\
**Post date:** [May 30, 2017, 2:20pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/1 "2017-05-30T14:20:52Z")

</div>

I’m trying to get the hang of Lwt, and I’ve run into [this old Gist](https://gist.github.com/komamitsu/1362149).

I’ve taken some time to make it work but I’m having a problem with the `>>` operator on line 32. The compiler tells me this is an unbound value, so I guess this is an old operator that has been removed since, but I can’t find the replacement for it.

Any idea?

P.S.: If you know of any “beginner-friendly” resources about Lwt (or concurrent programming in general), feel free to tell me about them, because it is a tough beast to tame.

---

<div class="post-metadata">

**Author:** ![antron](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/antron/32/62_2.png) [@antron](https://discuss.ocaml.org/u/antron)\
**Post date:** [May 30, 2017, 2:38pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/2 "2017-05-30T14:38:28Z")

</div>

Heya,

The `>>` operator is equivalent to `>>= fun () ->`, i.e.: `foo >> bar` is `foo >>= fun () -> bar`. The `>>` operator is deprecated.

Regarding beginner resources, there is the [Mirage Lwt tutorial](https://mirage.io/wiki/tutorial-lwt). Perhaps others can post more nice links. Note that the Mirage tutorial refers to `Lwt.t`s as threads, even though they are promises (it does point that out in the beginning, though). That is a fault of terminology that we are currently correcting throughout the Lwt docs. We are also writing new ones.

It’s a current priority to create nicer beginner resources. Also, I’ll be adding a link to the Mirage tutorial from the Lwt `README` shortly. Thanks for prodding me by asking this question 🙂

---

<div class="post-metadata">

**Author:** ![antron](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/antron/32/62_2.png) [@antron](https://discuss.ocaml.org/u/antron)\
**Post date:** [May 30, 2017, 2:41pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/3 "2017-05-30T14:41:58Z")

</div>

You may also be interested in reading the [Real World OCaml chapter on concurrent programming](https://realworldocaml.org/v1/en/html/concurrent-programming-with-async.html) together with @dkim’s nice [translation of the examples to Lwt](https://github.com/dkim/rwo-lwt#readme).

---

<div class="post-metadata">

**Author:** ![Richard-Degenne](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/richard-degenne/32/112_2.png) [@Richard-Degenne](https://discuss.ocaml.org/u/Richard-Degenne)\
**Post date:** [May 30, 2017, 3:02pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/4 "2017-05-30T15:02:45Z")

</div>

Great, thanks a lot. `>>` is the kind of things that are hard to look up on Google. 😉

I’ve read Real World OCaml, but having the Lwt examples is great. I’ll also give a look at the Mirage tutorial, it looks promising. I’ll keep an eye out for any new material. 🙂

---

<div class="post-metadata">

**Author:** ![avsm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/avsm/32/6_2.png) [@avsm](https://discuss.ocaml.org/u/avsm)\
**Post date:** [May 30, 2017, 3:18pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/5 "2017-05-30T15:18:36Z")

</div>

The slightly bad news is that we consider `>>` to be deprecated these days, since it is part of the camlp4 syntax extension to Lwt.

Most uses of it in our code are replaced by `>>= fun () ->` or similar uses. In general, there has not been much adoption of the PPX lwt extension in Mirage code since we retired the use of camlp4, and developers seem to prefer just explicitly using the standard `Lwt.Infix` operators.

---

<div class="post-metadata">

**Author:** ![antron](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/antron/32/62_2.png) [@antron](https://discuss.ocaml.org/u/antron)\
**Post date:** [May 30, 2017, 3:36pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/6 "2017-05-30T15:36:07Z")

</div>

There is also this [simple server example and walkthrough](http://www.baturin.org/code/lwt-counter-server/) ([code](http://www.baturin.org/code/files/counter-server.ml)) by @dmbaturin. It looks to be Camlp4-free.

---

<div class="post-metadata">

**Author:** ![dmbaturin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dmbaturin/32/2074_2.png) [@dmbaturin](https://discuss.ocaml.org/u/dmbaturin)\
**Post date:** [May 30, 2017, 4:03pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/7 "2017-05-30T16:03:47Z")

</div>

I still haven’t abandoned the idea to write a more structured and thorough, task-oriented tutorial. Doing it alone is hard though, so I really would like someone to collaborate.

---

<div class="post-metadata">

**Author:** ![Richard-Degenne](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/richard-degenne/32/112_2.png) [@Richard-Degenne](https://discuss.ocaml.org/u/Richard-Degenne)\
**Post date:** [May 30, 2017, 4:09pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/8 "2017-05-30T16:09:28Z")

</div>

Well, I don’t think I can help writing such a document, but I can provide feedback from a beginner standpoint, for what it’s worth.

---

<div class="post-metadata">

**Author:** ![dkim](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dkim](https://discuss.ocaml.org/u/dkim)\
**Post date:** [May 30, 2017, 4:22pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/9 "2017-05-30T16:22:13Z")

</div>

@antron @avsm The manual states that `>>` is included in the Ppx syntax extension as well as the Camlp4 syntax extension.

[https://ocsigen.org/lwt/3.0.0/api/Ppx\_lwt#2\_Sequence](https://ocsigen.org/lwt/3.0.0/api/Ppx_lwt#2_Sequence)

Is the Ppx extension of Lwt considered to be deprecated, together with the Camlp4 extension?

---

<div class="post-metadata">

**Author:** ![antron](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/antron/32/62_2.png) [@antron](https://discuss.ocaml.org/u/antron)\
**Post date:** [May 30, 2017, 4:38pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/10 "2017-05-30T16:38:23Z")

</div>

@dmbaturin I’d love to work with you on that, though I have to do several other tasks in Lwt first (contributor documentation, some big PR reviews). @Richard-Degenne your feedback would be very much appreciated 🙂

@dkim Yes, it’s supported in the PPX, though you can disable it with a flag. I’m under the impression that it’s in the PPX only because it was in Camlp4, though I may be wrong. Perhaps @Drup can say what is the status of `>>`. If deprecated or discouraged, I/we should update the docs.

My personal opinion is that `>>` should be avoided.

And, respond to edit, the whole PPX is definitely _not_ deprecated.

---

<div class="post-metadata">

**Author:** ![Drup](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/drup/32/35_2.png) [@Drup](https://discuss.ocaml.org/u/Drup)\
**Post date:** [May 30, 2017, 9:16pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/11 "2017-05-30T21:16:10Z")

</div>

I was somehow convinced I made that thing disabled by default …

So, yes, \>\> is mostly here because it was in the camlp4 extension. I’m of the opinion it should never have existed and I should not have ported it to ppx. It causes many issues, like users trying to write `let f x = foo >> x` or things like that. The fact that it looks like a normal operator doesn’t help.

We could deprecate it and add --sequence, then change the default state, I guess.

---

<div class="post-metadata">

**Author:** ![antron](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/antron/32/62_2.png) [@antron](https://discuss.ocaml.org/u/antron)\
**Post date:** [May 30, 2017, 9:35pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/12 "2017-05-30T21:35:08Z")

</div>

@Drup mind opening an issue in the repo? Maybe we don’t have to change the default state, but just emit a warning when `>>` is used, plus amend the docs. We can release that in 3.1.0 (July).

---

<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:** [May 30, 2017, 11:26pm UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/13 "2017-05-30T23:26:35Z")

</div>

Ah, syntax extensions.

In Async, we use a different PPX called [ppx\_let](https://github.com/janestreet/ppx_let) that’s designed for monads in general, and could be used for LWT as well if people wanted. In that mode, one could write:

```ocaml
let%bind () = some_other expr in

```

to get the equivalent of \>\> . We’ve toyed with the idea of supporting a monadic semi, like this:

```ocaml
some_other expr ;%bind

```

I’m pretty torn as to whether this particular oddity is a good idea, but I do quite like the remainder of the ppx\_let. ppx\_let also supports `match%bind` and `if%bind`, as well as parallel binds (`let%bind x = ... and y = ...`), as well as %map equivalents. These are especially useful when using an applicative, or a monad where the applicative part is especially important, like [Incremental](https://github.com/janestreet/incremental).

---

<div class="post-metadata">

**Author:** ![antron](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/antron/32/62_2.png) [@antron](https://discuss.ocaml.org/u/antron)\
**Post date:** [May 31, 2017, 12:22am UTC](https://discuss.ocaml.org/t/operator-in-lwt/296/14 "2017-05-31T00:22:31Z")

</div>

For the sake of completeness and clarity in this context, in case one doesn’t follow the link given by @dkim above, and somehow assumes that the PPX provides only `>>`:

Lwt’s PPX, while having a deprecated `>>`, [supports](https://ocsigen.org/lwt/dev/api/Ppx_lwt):

```ocaml
let%lwt () = expr in ... (* Recommended PPX alternative to >> *)
let%lwt x = expr and y = expr' in ... (* Parallel composition *)
match%lwt expr with ...
if%lwt expr ...
try%lwt expr with ... [%finally ...]
assert%lwt expr
for%lwt expr do ... done
while%lwt expr do ... done

```

It’s not as general as ppx\_let – it’s only useful for Lwt. Perhaps looking into ppx\_let should be some kind of future Lwt project (but I also guess we won’t have the personpower to do it soon).

The Lwt PPX also doesn’t have anything corresponding to `let%map`. It does have a proposal to add `;%lwt` as a replacement for `>>`:

[https://github.com/ocsigen/lwt/pull/307](https://github.com/ocsigen/lwt/pull/307)
