📜 ⬆️ ⬇️

Haskell in the present project

I had to participate in projects on c ++ with the number of lines more than 600,000. Therefore, it is difficult to name the project with 5000 lines present. Nevertheless, for haskel and motivation, just for fun is a considerable amount.

This small program [1] is written in free time, so it doesn’t have much time.

I would like to describe some impressions about the use of Haskel in practice.

')

User reaction


Criticism was. But, which is good news, not a word was said about the implementation language. Users simply do not care what you wrote your program. Using haskel, at the output we get the executable file on machine code. The user will even be glad that no interpreters and bytecode virtual machines are needed. And that does not need to install anything unusual to run this program.

Installation did not cause anyone serious problems. There were only minor problems, for example, so that cookies are disabled. Or on a 64-bit system a binary file was launched for 32-bit systems.

Haskell problems


Language problems

They say that for programming on haskel you need to have a doctoral degree. It is not true. Maybe those guys that develop language specifications and sophisticated libraries really need it. But the “user interface” of the language is very simple and intuitive. As well as for other programming languages, three classes of the parish school will suffice.

During the work on the project, there was only one problem related to the language. At a certain point, it was necessary to add one more monad to a large stack of transformers of monads [2]. What turned out to be a nontrivial task. With the help of reading the documentation and the friendly help of the Haskelists in irc, the problem was solved in the evening. Honestly, this place could have been made easier, but it was this implementation that allowed static typing to protect against a whole class of errors. If details are interesting, I will write a separate post.

Entry threshold and learning curve

There is also an opinion that the threshold of entry into Haskel is very high. And the learning curve is too stretched. On this occasion, I can say the following.

When I first began to study haskel, I solved one small problem. In Haskel there are no multi-line strings in the source code. That is, it is impossible to add large text to the source and get a valid string constant.
--  ,   text1 = " " --    text2 = unlines ["", ""] --    text3 = "\n\ \" 


I wrote a 600-line program that took a special text file as input and generated the source code on a Haskel with multi-line string constants. This allowed the development of web applications to embed all the texts directly into the binary.

The further I studied Haskel, the more I realized that this code is very bad. There were no state monads, the parsec library was not used for parsing. Everything was done by simple code with explicit indication of all parameters and using only trivial constructions.

But I easily understood this code even after 2 years. And he completely suited me. But the release of the project was approaching, for the assembly of which this utility is needed. It became a shame to release it in this form. Therefore, I sat down and rewrote it in half an hour on parsec [3].

Perhaps there is no problem with a smooth learning curve. Even beginners to learn Haskel according to scattered manuals write quite working code. And if we assume that the beginner will come to the team of experienced Haskelists, I think he will begin to write good code very quickly. Some successful industrial languages, such as C ++, require several years of experience.

Interoperability Issues with Other Systems

The real difficulties begin where haskel ends. That is, in places where the program interacts with the harsh outside world. For example, interaction with the operating system or with the user's browser.

For web applications, this is a common job of laying out web pages and developing javascript code. This also comes with cross-browser compatibility problems and other web-development delights.

The system side also requires a separate job. Installation scripts, initialization, interaction with system dynamic libraries. All this requires the same skills as any system development under linux.

Libraries. In addition to native libraries, a large number of wrappers around generic libraries have been created for haskel. But not all. During the work, I had to write my own wrapper around the PAM library [4], since there really weren’t any ready-made implementations. As it turned out, writing the interface to the code on Haskel is quite simple.

Proponents of python, when compared with Haskel, claim that almost all libraries have already been written for python. But I had to participate in one Python project, in which the existing package was rewritten from scratch to access the shared library. Because the existing code was terrible. So this advantage of a python is not so great.

We should also note the problem of creating packages for linux distributions. This is not so simple, the entire packaging infrastructure is tailored to traditional compilers and languages. The topic of creating packages for programs on haskel deserves a separate post. I was pleased that the programs on the hackle are going to even for such time-tested systems as Red Hat Enterprise Linux 5. To run an application on python, you need to get to work on python 2.4. Or try to run a newer interpreter there and get even more problems with installation and support.

What problems haskell relieves


I will not completely retell the paragraph “Why Haskel?” From the introduction from the official language site [5].

I will give a short list of the advantages of the language in this paragraph:

As practice has shown, they do not lie.

But from myself I would add one more item to this list. Programming on Haskel brings pleasure. Programmers of the mid-20th century, probably when the assembler first appeared, had the same emotions. The same simplification of work was in the transition from assembly to Fortran.

On Haskel, it is no longer necessary to manage named memory regions (variables). The developer gets only the named immutable values. On the representation of which in memory the compiler takes care of itself. This is the essential automation of a programmer’s work.

Well, let's wait until the business pays closer attention to Haskel. Risking the use of Haskel in production, you can still lose to get a significant competitive advantage.

[1] http://iptadmin.confmgr.org
[2] The link to the source, the necessary code in the authorize function
[3] http://patch-tag.com/r/etarasov/iptadmin/snapshot/current/content/pretty/util/ptmpl/src/Main.hs
[4] http://hackage.haskell.org/package/pam-0.1
[5] http://haskell.org/haskellwiki/Introduction#Why_use_Haskell.3F

Source: https://habr.com/ru/post/124270/


All Articles