5 Functional Programming Languages You Should Know
Whatsapp Pinterest

If you spend any amount of time reading up on programming trends on the internet, you’ll have heard about functional programming. The term is thrown about fairly often, but what does it mean?

Even if you’re aware of what functional programming is, you may be unclear about which languages are best suited for it. After all, not all programming languages are created equal. While you can apply functional programming paradigms in many languages, there are still some where you’ll feel much more comfortable.

What Is Functional Programming?

If you have a background in mathematics, you have a head start on functional programming. This is because the functional programming paradigm treats computing like mathematical functions. If you don’t have a mathematical background, this could leave you feeling confused.

Basically, functional programming treats functions and data as immutable. You pass data into a function, and it generally returns that data transformed or some other type of data. In functional programming, the function should never change the original data or program state.

There is a similarity to the Unix philosophy that each program should do one thing well. A function shouldn’t touch various parts of your program. Instead, it should take its input and give you an output.

Ideally, functions should be pure whenever possible in functional programming. This means that given the same input, the function’s output will always remain the same.

Functional vs. Object-Oriented Programming

This is a dramatic departure from something like object-oriented programming. In object-oriented programming, you often have a base object with various methods dedicated to changing either data or state that are part of that object. A method may even alter data or state if not explicitly stated.

In practical programs, sometimes this makes sense. That said, it can make programs harder to maintain, as it’s not always clear what is altering state or data. Functional programming was originally used in academic environments, but can also help to prevent these sorts of problems.

1. JavaScript

JavaScript logo

Some programming languages allow functional programming while others either encourage or even enforce it. JavaScript falls in the first category. While you can use functional programming paradigms in the language, you can just as easily use an object-oriented approach.

That said, there are plenty of functional programming paradigms built into JavaScript. Take, for example, higher-order functions. These are functions that can take other functions as arguments.

JavaScript has several functions that work with arrays like map(), reduce(), filter(), and others, all of which are higher-order functions. This lets you chain them together to quickly do all manner of things with an array.

While early JavaScript had some issues with mutability, newer versions of the ECMAScript standard provide fixes. Instead of the catch-all var keyword for defining variables, you now have const and let. The first lets you define constants, as the name implies. The second, let, limits the scope of a variable to the function in which it is declared.

2. Python

Python logo

Like JavaScript, Python is a generalized language that you can use any number of programming paradigms with. Python may have its downsides 4 Reasons Why Python Isn't the Programming Language for You 4 Reasons Why Python Isn't the Programming Language for You The Python programming language is extremely popular, but here are a few reasons why you might want to avoid Python. Read More , but functional programming isn’t one of them. There is even an introduction to functional programming in the official Python documentation.

To start, you’ll find many of the same map(), filter(), reduce(), and similar functions mentioned above built-in. As with JavaScript, these are higher-order functions as they take other functions as arguments. In Python, functional programming has an advantage in the form of the lambda keyword.

You can use lambda expressions in a few ways. One way to use it is as shorthand for simple functions. When assigned to a variable, you can call lambda expressions exactly as you would a standard Python function. The real advantage of lambda expressions comes when you use them as anonymous functions.

Anonymous functions work in JavaScript and other languages on this list as well. They come in especially handy when used with higher-order functions since you can define them on the spot. Without anonymous functions, you’d have to pre-define even simple additions as bespoke functions.

3. Clojure

Clojure programming language logo

Unlike JavaScript and Python, Clojure may not exactly be a household name, even among programmers. In case you’re not familiar, Clojure is a dialect of the Lisp programming language, which dates back to the late 1950s. This brings along with it a very specific way of doing things that happens to be perfect for functional programming.

Like other Lisp dialects, Clojure treats code as data. This means that the code can effectively alter itself. Unlike other Lisp dialects, Clojure runs on the Java platform and is compiled to JVM bytecode. This means it can work with Java libraries, whether they were written in Clojure or not.

Unlike previous languages on this list, Clojure is a functional programming language from the ground up. That means that it advocates immutability wherever possible, especially within data structures.

Clojure doesn’t expect all programs to be mathematically “provable,” but encourages using pure functions wherever possible.

4. Elm

Elm programming language logo

One of the newer languages on this list, Elm is a purely functional language initially designed by Evan Czaplicki in 2012. The language has gained popularity among web developers, specifically for creating user interfaces.

Unlike every prior entry on this list, Elm uses static type checking. This helps to ensure no runtime exceptions, with errors instead caught at compile time. This means less visible errors for users, which is a major plus.

The Elm compiler targets HTML, CSS, and JavaScript. In the same way that you can use Clojure to write programs that run on Java, you can write apps that use JavaScript libraries in Elm.

One major difference between Elm and other languages here is that you won’t find generic filter(), map(), and similar functions. Instead, these are defined by data type like List.map or Dict.map.

5. Haskell

Haskell programming language logo

Haskell is another statically typed, purely functional language. Unlike Elm, Haskell has been around for a while. The first version of the language was designed in 1990. The latest standard is Haskell 2010, while the next version is planned for 2020.

As we’ve already explored, Haskell’s purely functional nature means that by design, functions shouldn’t have side effects. This makes it well-suited to solving real-world problems despite functional programming’s roots in academia.

Despite its lack of mainstream popularity, Haskell has been employed in some widely used projects. The Xmonad window manager is written entirely in Haskell. Pandoc, which converts different types of markup to and from other formats also uses the language.

The standard map(), filter(), reduce(), and other higher-order functions are present, which should let you take concepts from JavaScript or Python to Haskell. If you want to learn more about the language, Learn You a Haskell for Great Good is a popular starting point.

Are You New to Programming?

Some of the above terms and languages may seem somewhat esoteric if you’re not yet a seasoned coder. That’s good, as knowing what you don’t know is one of the first steps in becoming a better learner.

Some of the languages listed above are better for beginners than others. Take a look at our list of the best programming languages for beginners 6 Easiest Programming Languages to Learn for Beginners 6 Easiest Programming Languages to Learn for Beginners Learning to program is about finding the right language just as much as it's about the edification process. Here are the top six easiest programming languages for beginners. Read More . You’ll notice there is some crossover between the two lists.

Explore more about: Functional Programming, JavaScript, Python.

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. André
    May 12, 2019 at 4:42 am

    Clojure can also compile to JavaScript using ClojureScript httpss://clojurescript.org/ (and the excellent shadow-cljs compiler http://shadow-cljs.org/). I've been using clojure for almost 3 years in production and would highly recommend it. The easiest way to learn is by reading Clojure for the brave and true https://www.braveclojure.com/clojure-for-the-brave-and-true/

  2. Tensor
    May 11, 2019 at 1:35 am

    Umm what?

    You don't really seem to understand what a Functional programming language is or why its useful... especially if you name JavaScript as a functional language. Its not a functional language despite the fact that functions are first class data. This is due to the fact that the data is not immutable nor are the functions themselves. You also pick some strange languages for this article. I can agree with Clojure and with Haskell but what about Scala, F#, ReasonML/Ocaml, or Erlang/Elixir? You could even make an argument that Rust supports a functional style. All of these would be better choices then your other three languages (Not that I dislike Elm its just very similar to Haskell in many ways).

  3. Jonas
    May 10, 2019 at 11:42 pm

    The person who wrote this article shouldn't have, because he doesn't understand the subject well.

    For example, the core definition of functional programming is _not_ that functions "treats functions and data as immutable". There are functions that change the original data sometimes (work by reference rather than by value), in some languages. And in JavaScript, functions are first-class data, which means they can rewrite themselves and are therefore not "immutable". Look up "lazy functions" for example.

    Another error: in describing JavaScript variables, the author says "...let, limits the scope of a variable to the function in which it is declared". No, all JS vars were always functionally scoped. What the newer 'let' does is limit the scope of a variable to the _block_ in which it's defined.

    Really you should find someone more knowledgeable to write, and to fact-check, these articles.

  4. Mr right
    May 10, 2019 at 7:30 pm

    Good job on missing all real functional programming languages...

    • Jim
      May 10, 2019 at 8:53 pm

      I mean, Haskell sneaks in at the end, but apart from that what a car-crash of an article.

  5. Andrii
    May 10, 2019 at 5:26 pm

    Where is real functional PL?

    • CodeBee
      May 12, 2019 at 4:48 am

      There is only two functional language on your list; Ocaml and F#. Kotlin is not a functional language, and Scala is hybrid at best.