[go: up one dir, main page]

Locally-openable monads in Lwtreslib

The aim is to provide convenient locally-openable modules that bring functions related to one specific monad (i.e., none, lwt, result, lwt+result, option) into scope.

Before:

let f () =
  … >>=? fun () ->
  … >>=? fun x ->
  … >>=? fun y ->


let g () =
  … >>= fun x ->
  … >>= fun blah ->

After:

let f () =
  let open Infix_Lwt_and_Result in
  … >>= fun () ->
  … >>= fun x ->
  … >>= fun y ->


let g () =
  let open Infix_Lwt in
  … >>= fun x ->
  … >>= fun blah ->

Note that, on these examples, it doesn't improve things much. However,

  • It'll make ok, Lwt.return, return more uniform and more beginner friendly. Same for error and fail: which is which?
  • It'll avoid introducing differently suffixed monadic lets for different monads. I.e., we can let open Infix_lwt in let* x = … in … and let open Infix_Lwt_and_Result in let* x = … in … instead of having to come up with different names for these different lets (let*= and let*=? would be the logical choice following the current convention).
  • We can integrate (into the design) some features to help with changing from one monad to the other.