Does ReasonML have an equivalent of F#'s Computation Expressions?
Asked Answered
M

1

8

In F# we have Computation Expressions, which can reduce boiler-plate and nesting when working in various computational contexts (async, optionals and so on).

  • Does ReasonML have an equivalent of this?
  • If so, what is the syntax?
Monroe answered 5/4, 2018 at 12:26 Comment(0)
T
10

By default, nope; no computation expressions. Reason is just another syntax still sharing all of the OCaml semantics, so a similar behavior is commonly achieved using modules, functors and composition.

However, Reason and OCaml have ppx rewriters, that allow extending the syntax to achieve this sort of things. There is already an open issue about a special syntax for asynchronous and awaitable computations.

Some useful ppx rewriters that are similar to computation expressions:

  • ppx_let: Monadic let-bindings
  • ppx_lwt: LWT programming, async/await
  • ppx_deriving: Haskell like type deriving, like for Show, Eqand Ord
Territory answered 10/4, 2018 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.