caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Milan Stanojević" <milanst@gmail.com>
To: Yotam Barnoy <yotambarnoy@gmail.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Question about Lwt/Async
Date: Tue, 8 Mar 2016 00:59:36 -0500	[thread overview]
Message-ID: <CAKR7PS9VqKf-Scf3x3MmrNzXM41CCYv4FB-sk1uEG1L4manQDQ@mail.gmail.com> (raw)
In-Reply-To: <CAN6ygO=ocZ9q_p75g=h1d+8zvqCQFPQW_AqM=2D5ZBvjAjQMmQ@mail.gmail.com>

> One of the advantages of OCaml over Haskell (which I'm not crazy about) is
> the fact that you don't have to constantly be stuck inside a monad. However,
> once you want to use these user-level threading libraries, you're
> essentially tied to a monad. It also means that the usage of any other monad
> from Lwt/Async code is out -- OCaml doesn't have the monad transformer
> infrastructure to layer monads easily as far as I can tell (am I wrong?). I
> mean, even in Haskell using Monad Transformers is a pain (IMO).

Are there any particular monads you have in mind?

My experience is that it's not a big problem in practice with Async (I
don't have experience with lwt but I guess it is similar) but I don't
really use a lot of monads (mostly just Deferred and Or_error)

With async, a good programming style is to keep asynchronous code at
the fringes of your application and make as much of your program's
logic synchronous. This is good for performance but more importantly
makes your code easier to reason about because you don't have to worry
about any interleaving and races since async runs code without binds
and maps as an atomic job.

This means that large parts of your code are just usual synchronous
ocaml code (you might not even open Async in a module) and you are
free to easily use any monad you want.

Of course, there are cases when you will run into issues, usually
combining Or_error and Deferred monads. Common case is when handling
rpcs in async. There indeed you are stuck for a bit in
Deferrred.Or_error monad but at some point you need to handle two
cases (Error and Ok) and you escape it.

      parent reply	other threads:[~2016-03-08  6:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07  1:38 Yotam Barnoy
2016-03-07  7:16 ` Malcolm Matalka
2016-03-07  9:08   ` Simon Cruanes
2016-03-07 14:06     ` Yotam Barnoy
2016-03-07 14:25       ` Ashish Agarwal
2016-03-07 14:55         ` rudi.grinberg
2016-03-07 14:59           ` Ivan Gotovchits
2016-03-07 15:05             ` Ivan Gotovchits
2016-03-08  6:55         ` Milan Stanojević
2016-03-08 10:54           ` Jeremie Dimino
2016-03-07 15:16 ` Jesper Louis Andersen
2016-03-07 17:03   ` Yaron Minsky
2016-03-07 18:16     ` Malcolm Matalka
2016-03-07 18:41       ` Yaron Minsky
2016-03-07 20:06         ` Malcolm Matalka
2016-03-07 21:54           ` Yotam Barnoy
2016-03-08  6:56             ` Malcolm Matalka
2016-03-08  7:46               ` Adrien Nader
2016-03-08 11:04               ` Jeremie Dimino
2016-03-08 12:47                 ` Yaron Minsky
2016-03-08 13:03                   ` Jeremie Dimino
2016-03-09  7:35                     ` Malcolm Matalka
2016-03-09 10:23                       ` Gerd Stolpmann
2016-03-09 14:37                         ` Malcolm Matalka
2016-03-09 17:27                           ` Gerd Stolpmann
2016-03-08  9:41     ` Francois Berenger
2016-03-11 13:21     ` François Bobot
2016-03-11 15:22       ` Yaron Minsky
2016-03-11 16:15         ` François Bobot
2016-03-11 17:49           ` Yaron Minsky
2016-03-08  5:59 ` Milan Stanojević [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKR7PS9VqKf-Scf3x3MmrNzXM41CCYv4FB-sk1uEG1L4manQDQ@mail.gmail.com \
    --to=milanst@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=yotambarnoy@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).