relude icon indicating copy to clipboard operation
relude copied to clipboard

Add support for monadic/applicative `let` syntax sugar

Open andywhite37 opened this issue 5 years ago • 5 comments

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:)

andywhite37 avatar Jul 18 '19 17:07 andywhite37

jaredly/let-anything has been deprecated. Instead see reasonml-labs/bs-let.

jihchi avatar Dec 27 '19 05:12 jihchi

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.

Toxaris avatar Feb 05 '20 10:02 Toxaris

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+ to Extensions.Functor
  • add and+ to Extensions.Apply
  • add let* to Extensions.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.

mlms13 avatar Feb 05 '20 16:02 mlms13

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.

andywhite37 avatar Feb 05 '20 16:02 andywhite37

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.

mlms13 avatar Apr 02 '20 17:04 mlms13