Functional Programming Languages: Past, Present and Future
To better understand this distinct class of programming languages, we’ll look at the definition, characteristics and the history associated with it.
Clojure, Elixir, Elm, F#, Haskell, Idris and Scala are all names you are likely to see among recommendations for functional programming languages worth learning. These are the languages in use today and which may well be in use in years to come.
A language like haskell features the most longevity, but even more recent ones like Clojure are actually rooted in earlier languages that continue to shape the evolution of functional programming (FP). (Read Straight From the Programming Experts: What Functional Programming Language is Best to Learn Now?)
To better understand this distinct class of programming languages, we’ll look at the definition, characteristics, and the history associated with it. (Check out INFOGRAPHIC: The History of Programming Languages.)
Why Is it Called Functional Programming?
FP gets its name from an approach to software construction built off the creation of pure functions. The foundation of all functional programming languages is Lambda Calculus (also written as λ-calculus). It is described as “the smallest universal programming language of the world.”
Accordingly, an FP is based mathematical functions that employ conditional expressions and recursion to perform the calculation. It includes the following characteristics:
- The data contained in it is immutable.
- It avoids side effects, which are any state changes which occur outside of a called function, and shared states.
- FP programming is easier to maintain as you don't need to worry about accidentally changing anything outside the given function.
- It has referential transparency.
- Modular design allows for small modules that can be coded quickly and are likelier to be able to be reused, which contributes to faster program development. Also the modules can be tested individually separately which can reduce the time spent on testing and debugging.
Rooted in Mathematical Functions
As functional programming is rooted in Lambda Calculus, its history would date back to the 1930s when Alonzo Church introduced it. Of course, it wasn’t used for computers then.
I wasn't until 1960 when an an American computer and cognitive scientist named John McCarthy published Recursive Functions of Symbolic Expressions and Their Computation by Machine. As a result of his research into such function, McCarthy created what is recognized as the first functional programming language: LISP.
A good summation of it can be found in The birth of LISP – a summary of John McCarthy’s original paper. The language had offshoots, including Common Lisp, Scheme and elisp, not to mention Clojure, which is currently very much in use.
As explained here, the capabilities built into LISP shaped the way functional programming is used even today.
- Use closures to implement static scoping. For example, in "let x = 3 in f = λ y. x + y", function f is not closed since it has a free variable x. To use f, it has to be bound with an environment that tells the value of x. A function with the environment for its free variables is called a closure.
- Invention of the conditional expression and its use for writing recursive functions. This has something to do with the evaluation order of expressions (see lazy evaluation).
- Use higher-order operations on list such as the mapcar function.
It also introduced what is called “garbage collection.” This is an important feature for functional langauges because they “tend to generate larger amounts of short-lived garbage than imperative languages do.“
Nearly two decades later, the next major advance took place at the University of Edinburgh where researchers defined the ML (Metalanguage). The researchers required a language that would work for their automatic theorem proving system (LCF).”
Another name associated with the year 1978 and Edinburgh is Hope. The source of the name is Hope Park Square, where Edinburgh's Computer Science Department was (but also for Higher Order Parameters and ‘springs eternal’ and so forth.)” Hope is distinguished as the first language to employ call-by-pattern.
1990 to present and beyond: Haskell
Haskell, named after the logician Haskell B. Curry, was the product of a committee that set out to work on formulating the language in 1987 and released the first version in 1990. The latest standard is Haskell 2010, and another version is slated for 2020.
Haskell has become the paradigm of modern functional languages, distinguished by “features such as higher-order functions, type inference, lazy evaluation and user-defined datatypes.”
Higher-order functions take other functions as arguments or return them as results. They allow for applications that could also be called currying. Doing that will individually apply a function to its arguments, and as each application returns a new function, it then accepts the next argument.
While laziness is generally considered a bad thing, it is does serve a purpose in programming. As explained in What is Lazy Evaluation? In contradistinction to “strict evaluation,” the approach of lazy evaluation is to evaluate only what is required.
Current Top Functional Programming Languages
Haskell is the most dominant name for this category, likely because of its extended history relative to other FPs. It also was a major influence on their development. Simon Peyton Jones, principal researcher at Microsoft and key contributor to Haskell, spoke about Haskell’s enduring influence both in its own right and in the way it shaped other languages.
Clojure is a new dialect of Lisp created by Rich Hickey. Ihat distinguishes Clojure from other LISP dialects is that it runs on the Java platform and is compiled to JVM bytecode. The advantage that offers is its integration with Java even those that were not written in Clojure.
As Hickey explains in Clojure.org says, “Clojure provides easy access to the Java frameworks, with optional type hints and type inference, to ensure that calls to Java can avoid reflection.”
It also says, that “Lisp's approach to code-as-data and its macro system still set it apart” from other Lisp dialects, and adds that its “maps, sets, and vectors are as first class in Clojure as lists are in Lisp.”
Hickey also shared his rationale for creating Clojure as reaping all the benefits of Lisp without some of its drawbacks. After setting out multiple bullet points under different headers, Hickey sums it up as follows: “In short, I think Clojure occupies a unique niche as a functional Lisp for the JVM with strong concurrency support. “
What’s different about Elm is that it uses static type checking, which aids in the elimination of runtime exceptions as the errors would be caught at compile time. As the Elm site boasts, “NoRedInk switched to Elm about two years ago, and 250k+ lines later, they still have not had to scramble to fix a confusing runtime exception in production.”
The absence of visible errors on the user end, is an obvious advantage for a language. That may be why it also feels justified in applying the description of: “A delightful language”, to itself.
As the Elixir's site describes itself: “Elixir is a dynamic, functional language designed for building scalable and maintainable applications.” Elixir is directed toward creating high-availability, low-latency systems. It runs on the Erlang VM, an ecosystem that is used by Heroku, WhatsApp, Klarna and others for “distributed, fault-tolerant applications.”
The advantage for Elixir programmers is that they can invoke an Erlang function without incurring any runtime cost.
F# runs on Linux, Mac OS X, Android, iOS, Windows, GPUs, and browsers. It is free to use and is open source under an OSI-approved license.
F# is used in a wide range of application areas and is supported by both an active open community and industry-leading companies providing professional tools.
Idris is a general purpose pure functional programming language that has featureds influenced by Haskell and ML.
As explained here, it is characterized by dependent types, which enables "types to be predicated on values, meaning that some aspects of a program’s behaviour can be specified precisely in the type.” It is also distinguished by being compiled, with eager evaluation.
Among the newest of languages (released only in February 2016), Kotlin was five years in the making and the testing. Companies like Amex, NBC Digital, Expedia, and Gradle use it. It’s not a pure functional language.
Among the benefits it offers is that it is more concise than Java programming. Some think it’s possible to cut out over a third of the lines of code. It also offers all the advantages associated with functional programming languages, including higher-order functions, extension functions and lambdas.
Its versatility make it suited “for any kind of development, be it server-side, client-side web and Android,” and it is working on becoming compatible with Apple’s iOS.
Scala is another hybrid in that it offers both object-oriented and functional programming.
What We've Learned
Telstra’s Big Data Analytics GM Mark Moloney sums up why we it is now time to embrace functional languages and why programmers should consider learning them:
One myth is that functional programming is hard or too academic. It is just another skill to learn. It takes time and practice to master — no different to the journey that developers went through to learn object-oriented programming in the late 80s / early 90s. Technology continues to evolve. It is one of the reasons I love software. Learning how to learn is as important as what you know.