Live data from Hacker News

Exploring ReasonML and functional programming

reasonmlhub.com

11–20 of 65 posts

Re: Exploring ReasonML and functional programming

#11
post #7
post #3

Why should someone unfamiliar with functional style programming be learning ReasonML rather than say, something like, haskell? Looking for concrete, technical answers.

when I started out to learn functional style programming I wanted to build a real project. I tried several languages out and I settled with F# because I just didn't like the enforced purity of Haskell and laziness as a default. It just cost me so much time to constantly think about IO that I was barely figuring out what I wanted to write. It seemed impractical to me and now with some more experience I still think it…

I can assure you that, with practice, Haskell can be a very practical language. Having IO in the types lets one reason about where the effects are happening, which is especially important when trying to solve real world problems with functional techniques (i.e. transforming unreliable streams of data).

Re: Exploring ReasonML and functional programming

#12

Someone will have to explain why I might pick ReasonML over Elm for front-end development. Elm's community seems very focused on making front-end development as intuitive and hassle-free as possible. ReasonML seems like Facebook just wanted to leverage a pre-existing community but couldn't bring themselves to adopt the syntax so rewrote it in-house.

No runtime. ReasonML is a language that has decent interop capabilities with javascript through the bucklescript compiler. You can use it to write drop in ready code segments into an existing codebase.

Hello world in ReasonML will get you a single line javascript output. Last I looked, the Elm bundle is in the 10s of kbs for something like that because you get the whole architecture.

Add is ReasonReact and it's a little more comparable obviously.

Re: Exploring ReasonML and functional programming

#13

Someone will have to explain why I might pick ReasonML over Elm for front-end development. Elm's community seems very focused on making front-end development as intuitive and hassle-free as possible. ReasonML seems like Facebook just wanted to leverage a pre-existing community but couldn't bring themselves to adopt the syntax so rewrote it in-house.

I am not advocating anything in particular as I am in the process of choosing the next language to learn. That said, I have watched some talks by Cheng Lou and some others about ReasonML.

Elm is just "Elm"... that isn't a bad thing and it seems like it is more mature at the moment.

ReasonML is Ocaml that plays nice on any screen anywhere thanks to Bucklescript. It also plays nice as a systems language. That is, unikernels... I am not even sure what they are, but they sound awesome and I want that.

Re: Exploring ReasonML and functional programming

#14
Maybe not the right place to ask, but "Better standard library" appears in the section detailing future improvements that ReasonML might bring to the OCaml ecosystem. How do they plan on doing this, given that the major standard library camps seem relatively entrenched in OCaml today? Which one does the ReasonML community favor/intend to contribute to?

Re: Exploring ReasonML and functional programming

#15
post #3

Why should someone unfamiliar with functional style programming be learning ReasonML rather than say, something like, haskell? Looking for concrete, technical answers.

You cannot go wrong by picking any statically typed functional language - Reason, Elm, F#, PureScript, Haskell, or even Idris. All of these languages share a similar style of programming that revolve around data that is described through a rich type system and program execution modelled as a series of pure functions that transforms values from one type to another.

For someone new to the Typed FP world though, Reason or Elm would be an easier starting point. Both communities are geared towards newcomers and have first-class support for front-end development.

My brief foray into Elm was very pleasant, and it is a community with great taste and aesthetics. Evan Czaplicki is wise beyond his age and is building a language that will last a long time. One reason why I would reach for ReasonML than Elm however is Reason's zero-overhead interop with Javascript. You can do this right in the middle of your code `[%%bs.raw console.log ("hey")];` and nobody will complain. This interop allows Reason to utilize the vast NPM ecosystem - so you can gradually adopt Reason in your front-end codebase. Your ReactReason code can use your plain React components and vice versa, and you can even use the bs-express library to write NodeJS applications with ExpressJS.

Elm aims to remain pure because it allows them to build a more solid ecosystem in the long run. It is a great choice as well, just that the shorter-term trade-offs make it slightly more difficult to work with existing Javascript code.

One angle in which Reason would be a better beginner language than Haskell is the number of concepts you have to understand before you can be truly productive with it. The shift from an imperative, dynamic world to a functional, statically typed world is already difficult enough. Reason/OCaml makes this transition easier because with it you can program in the familiar imperative style when you want, unlike Haskell where you need to rely on the elegant but takes-some-effort-to-grok Monads to tackle the Awkward Squad of I/O (https://www.microsoft.com/en-us/research/wp-content/uploads/...). And this might be controversial opinion - but the historical roots of Haskell as a language for bleeding-edge academic experimentation has lead to a certain kind of fragmentation that demands more effort from newcomers than a made-for-industry language would need. PureScript and Idris however have standardized on many of these things and might not share the same concerns. You still have to content with its laziness and purity. These are both practical and aesthetic choice in how to program, and they are very fun to explore. You just need to get started on some language in the statically typed FP camp to appreciate this long, deep rabbithole!

Re: Exploring ReasonML and functional programming

#16
post #3

Why should someone unfamiliar with functional style programming be learning ReasonML rather than say, something like, haskell? Looking for concrete, technical answers.

Haskell will take months of brain twisting before you really understand what is going on and can do anything productive. ReasonML, you could be up and running within a week. (Timescales are just a random guess, but you get the idea..)

Plus ReasonML isn't strictly functional. You can have side effects and mutation if you need. Obviously the purists may view this as a negative, but being able to eg. just get a random number without going through a ton of hoops can make things a bit less frustrating - especially if you are unfamiliar with functional.

Once you have a good grasp of functional through ReasonML, Haskell will feel a lot less daunting.

Re: Exploring ReasonML and functional programming

#17

Someone will have to explain why I might pick ReasonML over Elm for front-end development. Elm's community seems very focused on making front-end development as intuitive and hassle-free as possible. ReasonML seems like Facebook just wanted to leverage a pre-existing community but couldn't bring themselves to adopt the syntax so rewrote it in-house.

ReasonML has a much more advanced module system via Functors. As far as I know Elm has nothing like this. Despite a fair few arguments over incorporating type classes into Elm, the creator is pretty dead set against the idea.

This does make Elm a lot more approachable, but after a while can feel quite restrictive.

There is bucklescript-tea, which is the Elm architecture in for Bucklescript (and thus also Reason). It is pretty much an exact match, so technically there isn't really anything you are missing out on by going with Reason. In reality the Elm community is more mature which means there is more documentation and libraries available. However bucklescript does interface to javascript a LOT easier - which does open up a much wider ecosystem of javascript libraries.

Re: Exploring ReasonML and functional programming

#19
post #4

FYI for anyone who was fuzzy on the license/patent situation with the project: https://github.com/facebook/reason/commit/e8fb73ec6ff7c31367... (As of 12/2017, relicensed to straight MIT from BSD+patent.) Rauschmayer's work here makes me interested in the language and motivated to learn it. After reading more, only wish I'd explored for a recent project where I was working to implement a lot of functional patterns in…

> Any thoughts about ReasonML vs "straight" OCaml?

I've heard of (and from) web developers who say that they find OCaml impossible to read, but that ReasonML is easy and pleasant for them. So part of this is what you are used to, and another is subjective preference.

Re: Exploring ReasonML and functional programming

#20

Maybe not the right place to ask, but "Better standard library" appears in the section detailing future improvements that ReasonML might bring to the OCaml ecosystem. How do they plan on doing this, given that the major standard library camps seem relatively entrenched in OCaml today? Which one does the ReasonML community favor/intend to contribute to?

Base[1] is a good candidate for an OCaml standard library. It's got tons of functionality, results in binaries with small footprints, is cross-platform, and has a fairly stable API. It's also code that has been and continues to be battle tested every day in production systems at Jane Street. I'm biased, as I'm one of the maintainers, but trust me it's good, it's good.

[1]: https://github.com/janestreet/base

Post reply on HN