4

in this piece of code:

let rec write_from_exactly out s offs len =
    Lwt_unix.write out s offs len >>= fun n ->
       if   n = len then Lwt.return ()
       else write_from_exactly out s (offs + n) (len - n)
in ...

Although I can more or less guess what it does, I couldn't find any official definition on what ">>=" means and how it works.

1 Answers1

2

The symbol >>= is defined by Lwt, not by OCaml itself. It's an infix operator equivalent to bind. You can see the definition of bind in Lwt's documentation.

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
  • BTW, you can link directly to the definition in all ocamldoc-generated pages, but it's a bit tricky. Depending on your browser, do "Inspect element" or a search in the source to find the markup, and paste the id (in this case `VAL(>>=)`): http://ocsigen.org/lwt/2.5.1/api/Lwt#VAL(>>=) – antron May 02 '16 at 21:45
  • (I'll try to remember to do this. Maybe ocamldoc guys could generate something easy to copy/paste. Or maybe browsers should help with this?) – Jeffrey Scofield May 02 '16 at 21:50
  • I think ocamldoc should make values clickable, where when you click on one, it links you to the anchor, and you can take the anchor URL from your browser's address bar. But obviously the markup is not there yet. GitHub does this, for instance. The ocamldoc markup is a bit obsolete at this point, it has many structural problems as well. – antron May 02 '16 at 22:46
  • what's the latest news on an ocamldoc replacement? – user3240588 May 04 '16 at 08:51
  • would be more helpful if you explained what `bind` was instead of just linking the documentation. – Boris Verkhovskiy Jul 19 '23 at 21:40