I still need to wrap my head around the new let+, let*, and+,… syntax “operators”, but nevertheless just started using them. This post helped me to get started and the type system (thanks to merlin, ocaml-lsp) is a good guide, anyhow.
This is my question: Are there any conventions, when to use let+ vs. let*, e.g., one for monads, the other for applicatives, or so?
Have a look at @CraigFe operator lookup tool. There is also a nice explanation for those operators.
Wow, this is really cool! If not done, we should add a link on ocaml.org and/or ocamlverse.
It is nice that the community discusses conventions around let-operators. Speaking of conventions, a discussion about a let operator to mimic F#'s use
keyword for binding resources arose at https://github.com/ocaml/ocaml/pull/9887. The PR generated an interesting discussion based on actual code but I believe it is up to the community to pick up the suggestion from there.
For completeness, I am citing the linked lookup tool:
let*
This is a Monadic binding operator.
val ( let* ) : 'a t -> ('a -> 'b t) -> 'b t
… for some type operator t
. This operator could have any type, but conventionally we use it to implement the monadic bind operation for a type, making it the syntax equivalent of the infix operator ( >>=
).
let+
This is a Map binding operator.
val ( let+ ) : 'a t -> ('a -> 'b) -> 'b t
… for some type operator t
. This operator could have any type, but conventionally we use it to implement the map operation for a type, making it the syntax equivalent of the infix operator ( >>|
).