ReScript equivalent of IO in Scala/Haskell/Other

I’m new to ReScript (and I really like what I’m seeing!), and also a relative novice with FP, but I’ve recently been spending time trying to deepen my understanding of FP concepts. Some of what I’ve been looking at recently uses examples in Scala, so I’ve recently been reading about the IO type for dealing with side effects. Is there an equivalent mechanism (or technique) in ReScript?

2 Likes

I’ll let others answer your question, but if my interests were in trying out something like an IO type in a setting like ReScript, I would start with using Elm and then experiment with ReScript after that.

My personal understanding of ReScript is “a better TypeScript, with an emphasis on functions over classes, for Javascript developers”. Some of that emphasis on functions will result in libraries that focus on using stronger error checking.

Purescript, Elm, Scalajs + cats/zio, reflex-frp and other haskell based approaches, and some libraries within JSOO, focus more on pure functional programming.

4 Likes

In ReScript the emphasis is on pragmatic typed FP for shipping products. So there is less emphasis on IO and related ‘category theory’-based techniques. But there are third-party libraries based on those techniques, e.g. https://reazen.github.io/relude/

3 Likes

I took a quick stab at porting relude to rescript last night. Didn’t get too far before I figured out that infix operators aren’t available right now so that may not be an option near term?

Ony two days into rescript myself though so may be more to it.

A

1 Like

True, custom operators are not really usable in ReScript right now.

1 Like

Thanks for all of the input. After a little bit of investigation, I see that creating some basic support for IO in ReScript should be fairly easy with a few functions, without needing to go off the deep end, but providing a bit more clear delineation between the pure and impure parts of an app. I’ll continue to look back at the relude repo as I gain a bit more FP and ReScript knowledge.

2 Likes

Thanks for the link. Would you mind elaborating a bit on your answer?

Category-theory-based techniques (monads, monoids, semigroups, applicatives, and abstract versions of those) are not very common or idiomatic in OCaml/Reason/ReScript; the language doesn’t enforce it like Haskell does. Here’s what the creator of OCaml has to say about it: https://discuss.ocaml.org/t/io-monad-for-ocaml/4618/7

But–I should add that nowadays monadic and applicative style are becoming more common in OCaml with convenient use of let-operators (not yet available in ReScript). Just not more advanced, abstract versions of those techniques.

6 Likes

I would avoid introducing IO types/functions, and spend that time on improving relude incrementally. IIRC, scalaz/cats used to have memory and stack issues in their early implementations, and eventually have been adopted in production settings now after rounds of optimizations.

4 Likes

Of the people interested in this thread, I am curious about whether people are actively using tablecloth or relude?

2 Likes

I decided to create bindings for papaparse instead of using relude-csv, because relude-csv notes that is not ready for production use.

I have started to development implementation FP features for ReScrip - GitHub - snatvb/re-fp: Functional programming library for ReScript
But it in early state of development

1 Like