relude
relude copied to clipboard
Add support for monadic/applicative `let` syntax sugar
It would be nice to have a better way of using monads than nested >>=
functions. OCaml 4.08.0 has the new let+
/let*
operators for monads and applicatives, but it's not clear when Bucklescript will update to that version, and what Reason support will look like (although I don't see why it wouldn't work in Reason if it works in BS). Once those are available, I imagine that will be the canonical solution to this.
I saw there was some work to use ppx_let in bs-abstract
, but there was a comment that it doesn't work in Reason yet - not sure if that's still accurate.
Another option might be let-anything - I looked at it briefly, and it has a bsconfig.js, so maybe it would work (although I don't know exactly how it works or what it does :smile_cat:)
jaredly/let-anything
has been deprecated. Instead see reasonml-labs/bs-let
.
We are looking at adopting relude
right now, and reasonml-labs/bs-let
is a must-have for us. We even considered wrapping relude
just to add the let_
functions.
It looks like Reason is very close to getting proper support for the monadic/applicative let syntax, so we've sort of been waiting for that to land, at which point we should be able to:
- add
let+
toExtensions.Functor
- add
and+
toExtensions.Apply
- add
let*
toExtensions.Monad
...which should make the new syntax Just Work for everything that implements those typeclasses (List, Array, and Option; IO and Result with a known error type). At that point, it might also be worth adding some specialized versions like let.opt
and let.io
. I'm not as sold on that, but I can understand the argument that it helps with readability, and it gets around name collisions nicely.
In the meantime, I think we'd definitely be open to a PR adding bs-let support, but @andywhite37 and I are probably unlikely to implement that ourselves while waiting for official Reason support for the syntax.
I'd say to hold off on bs-let support, because that's likely to just go away when the official language support comes. bs-let support could be added at the application level or a separate library of Functor/Apply/Monad/etc. extensions if people really need it.
If the native let*
/etc. binding stuff tanks, we could reconsider bs-let support.
Just wanted to link this issue up with #256. The PR isn't ready to go until we get a Bucklescript release, but if people want to start playing around with it now, any feedback would definitely be valuable.