Elm Language. Functional programming on the web.
- February 3, 2018

As you probably noticed there is a clear trend of functional programming in IT. This is due to the growing volume of data, desire to process interactive information and in general it helps to reduce the amount of code.
Canonically, it so happens that the web is the last IT domain that you will think about when it comes to AF. Although it is often here that you have to deal with dynamic data flows and react to the user’s last actions as the static framework still suits both sides. But this will not always be the case. If you want to go far in this area, you’ll have to learn PHP in JavaScript or just pay attention to Elm.

Where did it come from?

Elm was not meant to be a language that should turn the world and the web. It was coined by student Evan Chaplicki for his thesis. He wanted to show how easy the web development would be through functional programming. The idea was a success: a year later when settling in the company Prezi it took up full-fledged language development. In 2016 he moved to NoRedInk and launched the Elm Software Foundation project where everyone could participate in the development of the language.

Benefits

More often than not, the main purpose of using the FP is to focus not on private implementations, as in the imperative case, but on streaming, dynamic data. In “classical programming” the expression z = x + y is used to orient the state of variables to the moment of execution. Further changes in the values of x and y on z will not affect it in any way. In reactive programming (RP), the result of the expression will be recalculated each time the arguments are changed. If you work with the web then you’re probably familiar with the most popular implementation of RP – ReactiveX – a library designed to simplify event programming. Elm is a tool from the same series.
Among the advantages of the language are the following:

  • Compile in JavaScript. This is a universal tool for private implementations in the popular language of the web and not only.
  • No runtime errors. All of them are caught at the compilation stage. The confirmation of this theory is more than 80 thousand lines of code in the performance of NoRedInk and no Runtime errors for 2 years.
  • Performance. The official site compares software implementations made in different frameworks. Elm’s performance is insignificant but remains in the lead.
  • Syntax

    Syntax can also be attributed to pluses since formally it’s all the same JavaScript only without a series of service symbols. In any case, it’s easy to get used to it:
    import Html exposing (text)
    import String
    {- Usually we name all the functions we use. So the following
    function is named `increment` and we can refer to it by that name
    anywhere in this file.-}
    increment n = n + 1
    add1 = \ n -> n + 1
    main = text (toString (increment (add1 40)))

    The reverse side is itself programming on Elm. As in any case, the FP, it is necessary to think in broad categories. As practice shows, perestroika will last for a couple of hours. After the head has worked in the right direction you’ll fully enjoy the language and its capabilities.

    How to learn

    The main source of wisdom, like any young language use the official website. There is a tutorial for the language, FAQ and a few examples.
    Video presentation of Evan Chaplicki is devoted to reactive programming on Elm and is available on YouTube.
    For fans of paper editions, there is a rare copy – “Elm in Action” by Richard Feldman. True, it will be hard to get it and you’ll have to sweat with shipments from the USA.
    Myself, I think that it is much more convenient to download and print a book devoted to Elm from the GitBook resource. It is the most complete, competently arranged from the existing on the Internet including the original Chaplicki.

    Prospects

    Unfortunately, the development of Elm Software Foundation stopped all the same in 2016. Sam Chaplitski already almost does not work on Elm. Instead, he travels the world speaking at conferences and universities education why it is a language of the future.
    Firstly, it’s really a convenient language and it slowly increases the number of followers naturally. For example, in the TIOBE rating, it already enters the first hundred. Secondly, Elm has practically no competitors. Anyone who can be ranked among them or cover a larger layer of programming or almost unknown. Thirdly, who knows. Maybe tomorrow Evan or NoRedInk will seriously take up development and then Elm will become mainstream.

    In general, if you work on the web be sure to meet Elm. A lot of time will not be lost but for sure you together can spend a couple of fun hours.

    recommended
    Smart Order Router. What is this?

    One of the key features of FinSafe’s trading platform is Smart Order Routing. A professional trading platform that a traditional …

    9 useful abbreviations in the JavaScript syntax

    Various shortcuts increase your productivity and make the JavaScript code shorter. And since short records are absolutely equivalent to long …

    Several reasons to explore Swift

    Swift is applied to create applications for Mac and iOS acting as a possible replacement for Objective-C. The latter, though …