-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define let*, and* #775
Define let*, and* #775
Conversation
Lwt supports ocaml versions starting from 4.02, so these new operators will fail on versions older than 4.08. I think this will need some dune machinery to ensure that this new syntax only gets exposed on ocaml >= 4.08. One example of this that i've seen in the ecosystem is the containers library that supports the new operators on ocaml > 4.08 c-cube/ocaml-containers@bf0227d |
I haven't had a chance to look at the PR in detail yet, but the |
I think the choice for A variant of I'll port to < 4.08, add a couple tests, and merge. |
Actually, a safer choice is not to define |
I also think that Lwt should just provide Lwt (i.e., promise) monad-like combinators. Combining monads is its own can of worm and each project might want to do it on its own term. It's relatively easy for a project to write |
I can live with that: let (and*) = Lwt_result.both is not too annoying to duplicate across modules, and makes the choice somewhat more explicitly available for code reviewers. Although, this does limit the utility of having a Also, the error is not dropped per-se, the resulting promise is still wrapped in a
This has practically not mattered to me personally, because in either case, I cannot continue with the remaining computation - it's a small debugging inconvenience to not know which of the two situations happened. Not sure if you want to add the applicative syntax
That'd be great thanks! Not sure if this involves packaging it as a separate libraries: |
I had in mind not to add
Apart from the distinction, in the "both" case, one of the errors is also dropped. If we could guarantee that the error type has an operation
Could you try it in this PR, then? It doesn't require anything fancy, I linked in a prior comment to the only two lines you should have to add for this. |
Well, I guess |
Yes, in practice, I'm mostly using
I agree it's not ideal. Not sure how it might be done better though. I'm not familiar enough with haskell to understand some of their monad transformers examples, but I'm sure the situation would have come up there before? Maybe we can seek out opinions on discourse?
Will do! |
Looked for inspiration at That seems not so useful. If we were to go with a functorized solution, it would look something like this: let _ =
let open Lwt_result.Syntax.Make(struct type t = string let combine_err = (^) end) in
let* p1 = thing1 ()
and* p2 = thing2 ()
and* p3 = thing3 () in
(* do your thing *) I would frankly not enjoy using/reading that. I vote to warn people with comments in the absence of a smarter proposal. |
Personally, I would be okay with using If people do want a version with combine, that can be exposed as an additional functor, so clients who prefer to combine can use the functor |
Not in that code. The promises Lines 2574 to 2582 in 2412006
Here, it relies on Actually, we probably want this property for Lines 1948 to 2159 in 2412006
|
If getting commutativity is too much of a pain, we can probably just leave it as a note in this issue. I think you should be able to get it by having |
…e Lwt_result.both commutative, add some tests
If you're having trouble with Bisect, you can drop support for it. I will work it back in later. Alternatively, you can test the OCaml version and add |
Thanks @code-ghalib! And to all for discussion! |
I'll release this in 5.3.0 this week. |
This is now out in Lwt 5.3.0. |
Proposal to add a syntax module to both
Lwt
andLwt_result
now thatlet*
andand*
are available in vanilla OCaml without ppx.I've made an arbitrary choice while defining
Lwt_result.both
that works for most cases, because I cannot think of a solution that is both general and easy to use. I could avoid the arbitrary choice like so:But then defining the syntax module would probably involve a functor which is not that nice to use.
I'm open to suggestions - the main motivation is to not have to redefine these all the time for being able to use monadic syntax.