Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?
like image 736
sdgfsdh Avatar asked Apr 05 '18 12:04

sdgfsdh


People also ask

Is ReasonML fast?

ReasonML modules are compiled independently, with an extreme focus on speed, allowing builds to scale with multi-core CPUs for insanely fast build times. It's multiple orders of magnitude faster than TypeScript, incremental builds are generally complete in half a second or less (often under 100ms).

Is ReasonML compiled?

It supports native and JavaScript as compile-targets Supporting native and JavaScript as compiler targets allows code to be “written once, run anywhere”.

Who uses ReasonML?

Who uses ReasonML? 12 companies reportedly use ReasonML in their tech stacks, including Instagram, Stack, and Ruangguru.


1 Answers

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
like image 82
Marcelo Camargo Avatar answered Oct 21 '22 07:10

Marcelo Camargo