Here is something I learnt from dune. Since we use Lwt stuff all over the place, it makes it tricky to use
let constructs since you have to bind things explicitly. If you do something like:
let (let*) = Lwt.bind let (and*) = Lwt.both
You can replace
let some_string : () -> string Lwt.t with
let* some_String : () -> string which makes reasoning about it later easier.
This hopefully will save having to write
>>= and match on
Error all the time
In fact, there even is a
ppx_lwt package (or something like this) that allows you to have these notations defined I think.
If you want to experiment with replacing a few monadic binds with such lets, please go ahead.
I think the ppx package is a bit more verbose, you would have to write something like
(let*) operator was introduced in 4.08: https://ocaml.org/manual/bindingops.html
Yup the ppx package was mainly useful for pre 4.08 time
tho it may have some more fancy things that 4.08 doesn't
Even simpler actually,
open Lwt.Syntax gives us access to let*
I guess if we use ppx we can start using multiple versions of let especially for result
But this has a risk of being completely unreadable
Let's try with just
Lwt.Syntax for now.
I'm looking for a projection for Lwt. We have the pair as
Lwt.both : 'a Lwt.t -> 'b Lwt.t -> ('a * 'b) Lwt.t, do we have something like
Lwt.fst : ('a * 'b) Lwt.t -> 'a Lwt.t?
oh nevermind it is just map
Just realised that there is Lwt_result.Syntax which was what I was wanting before
I'm gonna experiment with it later since I don't want to do too many things at once.
Last updated: Dec 07 2023 at 09:01 UTC