r/functionalprogramming • • Feb 07 '18

Question Purescript vs ReasonML/Bucklescript in 2018?

Which language would you pick for a new project in 2018, that has an imporant browser component?

Last year I looked into both, found the OCAML documentation and error messages extremly lacking, and enjoyed purescript much more.

However, it seems that purescript stagnated since and reasonml is building up steam.

What's your guys impression as of early 2018 regarding advantages, documentation, ecosystem (JS interop, well documented libraries) and future-proofedness (is this a word?) of these platforms and which one would you pick?


Edit one month later: Greetings to the visitors from the future! After playing around further, I gave up on Ocaml. For me

  • Error messages were completley useless. Everything would yield a "syntax error" with a seeming random line-number. In many cases the error message wasn't described, but encoured me to send pull requests with an updated message. These were obviously beginner mistakes, so nothing too fancy, and it forced me to scan every line manually to make sure all the ; and ) were in place.

  • I never got warm with the reason syntax. The javascripty look of reason made it more difficult to write than original ocaml/bucklescript, especially when to put ; {} () or not.

  • Tutorials/docs are rare and confusing. I never knew if I was learning Reason, Bucklescript or Ocaml

  • The toolchain only works if Reason, Bucklescript, Merlin and Ocaml are in very specific versions. Obviously the error messages you get are shit, so I spent far too much time on getting it running and I had to compile from source. Also, ReasonReact is it's own framework, so it's one more layer detached from react and data needs to be handed around between the components. All in all, updates are unpredictable and I don't trust the upgrade path.

  • Server side ecosystem is practically non-existent for modern use cases.

  • Apparently the majority of users are French students who learn Ocaml at university and there is very little adoption outside.

Final verdict for me personally: Unless there's a french guy in your team who already knows it, troubleshooting and boarding is hell and a time vapire. Also given the low maturity of the framework (error messages, old ocaml version, tutorials), I don't trust its upgrade path.

Maybe you get better results, but for me it's not worth it.


Purescript: Stagnated, but still nice. The React frameworks are terribly slow in benchmarks up to 8x slower than most of the field. For complex client side calculations and limited UI with a team that already knows haskell, I'd probably pick this.


Clojurescript: I stumbled upon it because its react frameworks perform amongst the fastest with less code, it's functional and immutable (with escape hatches). It's not typed, but it has Spec, which allows for quickcheck type autogenerated test cases, spec reuse for runtime validation and even regex and code-defined validation for what values are allowed into a type. The compiler is quick and clojure on the server integrated with the java ecosystem, it also has frameworks for react native.


All in all, this may sound blasphemous, but for me the most useful functional, typed frontend language is still Typescript with Ramda and Immutable.js. That gives me ADT, function composition, immutability, lenses, etc, with a rich ecosystem and easy boarding. Only thing I miss is type inference which makes me retype interfaces and types all over the place. For UI oriented applications Clojure(script) with Spec seems a nice fit. (I didn't check elm due to mounting negative feedback about breaking changes between versions). To use even more typed features purescript still the best, but be concious of the performance penalty.

26 Upvotes

22 comments sorted by

View all comments

7

u/saylu Feb 07 '18

My company uses PureScript (with Halogen) for the frontend of our web app with Python on the backend.

PureScript is mature enough for our entire frontend to be built in the language; we’re halfway through transitioning from an Angular app. Halogen has scary types when you get started, but once you’ve been working with the framework for a week or two they start to become second nature. We’ve enjoyed working in the language and have already seen a marked improvement in the reliability of the app where Angular has been replaced by Halogen.

The greatest weakness we have experienced so far is a lack of great components like typeaheads, day pickers, and so on ready to go for Halogen. We’ve needed to implement several of these ourselves where we might ordinarily have reached for an out-of-the-box solution like react-autocomplete. Yet this is an annoyance, not a dealbreaker.

As far as your points, I can’t speak to ReasonML but can share about PureScript:

  • Advantages The standard mix from functional programming: stability, no runtime errors, easy refactoring, easy concurrency, high ceiling for abstraction, great data modeling, etc. PureScript also has a tremendously helpful community in the functional programming Slack channel (https://fpchat-invite.herokuapp.com) and we receive help from core contributors at least weekly.

  • Documentation Core PureScript has great documentation (see the PureScript book, the Halogen guide and example repos). However, most of the rest of PureScript learns from Haskell by having mediocre documentation. You’ll need to become familiar reading types and briefly checking source code to see what’s going on. That said, we’ve rarely had trouble with documentation; most functions are self-explanatory and the functional programming Slack is great for filling in the gaps.

  • Ecosystem This is hard to answer without knowing specifically what you’re building. We’re building a complex web application involving lots of forms, data management, some visualization, etc. and haven’t had trouble. JS interop is a strong point of PureScript; right now we’re just dropping Halogen components as full replacements to most of our Angular app. Some PS libraries (like Data.Array) are wrappers for core Javascript functionality. It’s quite easy to do.

  • Future-proofed-ness Hard to say. There are companies invested in PureScript (SlamData is an obvious one; I work at Conde Nast), and it’s got an active community. You’re safe for at least the next 5 years, but after that, who knows? The web moves fast.