What is the simplest functional programming language for those who have experience in imperative languages?

I would like to learn a functional language to broaden the horizon. I have knowledge of Python and C / C ++, and I want the language to be easily mastered by someone who comes from the imperative field of languages. I don't care if this language is enough. I just want a language to learn basic functional programming, and then I will try to make a more complex (and powerful language).

thanks

+6
source share
6 answers

I recommend pure-lang for these pedagogical purposes. It is also very powerful. If you want something more popular / with more community support, then I would recommend Scheme or OCaml, depending on whether you prefer to deal with unfamiliar syntax (go to Scheme) or deal with an unfamiliar type (first with OCaml ) SML and F # are slightly different from OCaml. Others mention Clojure, Scala, and Haskell.

Clojure is a variant of the scheme, with its own idiosyncrasies (for example, without tail call optimization), so you can start using this method with Scheme. I would expect you to have an easier time with a less idiosyncratic implementation of the Scheme. Racket is what is often used for training. Scala looks fundamentally similar to OCaml, but it is based only on chance acquaintance.

Unlike Haskell, the other languages ​​mentioned have two advantages: (1) the evaluation order is evaluated by default, although you can get a lazy rating by specifically requesting it. In Haskell, it's the other way around. (2) Mutation is available, although most of the libraries and code you see do not use. I actually believe that it is pedagogically better to learn functional programming and at the same time monitor how it interacts with side effects and work its way into a monadic-style composition along the way. Therefore, I believe that this is an advantage. Some will tell you that it is best to throw more quarantine mutaton processing at Haskell first.

Robert Harper at CMU has good blog posts on learning functional programming . As I understand it, he also prefers languages ​​like OCaml for learning.

Among the three classes of languages ​​that I recommended (Pure, Scheme and friends, OCaml and friends), the first two have dynamic typing. The first and third have explicit reference cells (as if in Python you limited yourself to never overestimating the variable, but you can still change what is stored in the list index). The scheme has implicit reference cells: the variables themselves look mutable, as in C and Python, and the processing of reference cells is performed under covers. In such languages, you often have a certain form of explicit reference cell (as in the example I just gave in Python, or using mutable pairs / lists in Racket ... in other schemes, including the Scheme standard, these are the default / pairs lists).

In one of Haskell's merits, there are some textbooks for him. (I mean this sincerely, not maliciously). Which books / resources to use is another controversial issue with many wars / closed issues. SICP, as others have recommended, has a lot of fans, as well as some critics. It seems to me that I have a lot of good choices. I will not continue to dwell on this debate.

+8
source

First read "Structure and implementation of computer programs." I recommend Lisp (for example, this is a dialect scheme) as the first functional programming language.

+4
source

Another option is Clojure, which I make clear is more “pure” functional than Scheme / Racket (don't ask me for details here) and may be similar enough that you can use it in conjunction with SICP (Structure and interpretation of computer programs , a recommended book also suggested by another answer).

+2
source

I would like to learn a functional language to broaden the horizon. I have knowledge of Python and C / C ++, and I want the language to be easily mastered by someone who comes from the imperative field of languages. I don't care if this language is enough. I just want a language to learn basic functional programming, and then I will try to make a more complex (and powerful language).

Great question!

I did BASIC, Pascal, assembler, C, and C ++ before I started doing functional programming in the late 1990s. Then I started using two functional languages ​​at about the same time, Mathematica and OCaml, and used them exclusively for several years. In particular, OCaml allowed me to write imperative code that looked like the code I wrote before. I found this valuable as an apprentice because he allowed me to compare the different approaches that made ML benefits obvious.

However, as others have noted, the main advantage of Mathematica and OCaml is pattern matching and technically unrelated to functional programming. Subsequently, I examined many other functional languages, but I have no desire to return to a language that lacks template matching.

+2
source

This question is probably off topic, because it will lead to endless language wars, but here is a general tip:

There is a class of functional programming languages ​​that are sometimes called “mostly functional” because they allow you to use some imperative functions where you need them. Examples include standard ML, OCaml, F #, and Scala. You can think of one of them if you want to be able to access the functional idiomatic style while still being able to achieve things in reasonably familiar ways.

I have used standard ML in the past, but if you are looking for something that is slightly different from the learning curve, I would personally recommend Scala, which is my second favorite programming language. Reasons for this include the prevalence of libraries, a healthy-sized community, and the availability of good books and tutorials to get you started (especially if you have ever had any relationship with Java).

+1
source

One element that has not been discussed is the existence of a special pattern matching syntax for algebraic data types, as in Haskell, all ML flavors, and possibly several other languages ​​mentioned. The pattern matching syntax usually helps the programmer consider their functions as mathematical functions. The Haskell syntax is quite complex, and its implementations have rather bad parsing error messages, this syntax is a good reason not to choose Haskell. The scheme is probably easier to learn than most of the other options (and Scheme probably has the king of all macros), but the lack of pattern matching syntax pushes me away from it to introduce functional programming.

+1
source

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


All Articles