Fp-ts vs rescript - which is best for functional programming

To put it another way, you actually don’t need to dive deep into a Functional Programming rabbit hole to be productive, ship good quality code, and avoid most bugs. You just need to follow some basic best practices like avoiding global state and unbounded use of side effects.

But on the other hand, you do need a solid type system that actually isn’t full of hidden pitfalls. If you don’t have that, then no amount of Functional Programming can help. This is what ReScript gives you that TypeScript doesn’t.

8 Likes

As Yawar mentioned, types are pretty powerful. I suggest watching as much of Scott Wlaschin talks to get a good feel on how to use them. F# syntax is a bit different to ReScript, but not by much.

For example:

F#
type Apple = AppleVariety of string

ReScript
type apple = AppleVariety(string)

I’m not sure if you’re implying that ReScript is functional first?

Sorry, ReScript is a descendant of Reason/OCaml, so it is functional first.

I’m curious what you don’t like about “Task”. Although I’m very new to fp-ts and ReScript I do think that Task together with chain, map, fold operators is much more readable than “then” and I was also surprised to see async await being requested for ReScript as I very much prefer pushing errors to the forefront like this fp-ts overview: Error handling, the functional way (part 1) | Troika Tech

It’s not that I don’t like it. I am just saying you lose it. However, you can easily write your own Task in ReScript. ReScript provides a type system where you can build this or use Result and Option which are the kind of building blocks you need for handling almost all situations. Or you can just use or build off the many Promise implementations.

I want to kinda show you how that example article would look in rescript so imagine this implementation

Our final code would look kinda like

I did this off the top of my head, and with no implementation, it may or may not be 100% correct, but it should be close.

1 Like

Thanks again @seancrowe and others - nothing beats an explanation in code, though. That’ll be helpful when I try to rewrite the fp-ts code I have now, using ReScript, which I’ll definitely be attempting after all these great answers.

1 Like

When you try ReScript, consider using the reducer hook more to get some more FP style

Also, I would try ReScript, f#, elm, and probably consider ReScript or elm if I was trying to use it at work instead of hobby.

Rescript has some very experienced front end devs. Other communities have a mixture of experience levels.

2 Likes