be able to write a program pretty quickly
and still have high assurance it’s going
to do what you expect,” Wadler says. For
instance, the New York-based international trading firm Jane Street Capital
uses Ocaml, a dialect of ML, one of the
earliest functional languages.
Wadler is also a senior research fellow for IOHK, a Hong Kong-based company designing cryptocurrency, a digital
form of money of which bitcoin is the
most well-known example. The ease
of creating and validating programs
written in functional languages makes
them than appealing for such applications, Wadler says. “There’s a huge
amount of money that’s at stake there.”
Matter of Opinion
Just what counts as a functional language can be open to interpretation.
“Haskell and ML are widely considered
to be functional. Languages like C++
or C and even Java are considered to
be imperative,” Diatchki says. “Then
there are languages like Scala, which
sort of depends on who you talk to
whether they’re functional or imperative, because they support both styles.”
Often, programmers choose the style
that suits them best, or even employ
both in different parts of their code.
To Diatchki’s thinking, imperative
languages are more like recipes, laying out a series of steps to accomplish
a task, while functional programming
is more like a calculator, except that it
manipulates more than just integers.
“You type in a big expression and say,
‘what is the result now?’” He would not
consider a language functional, he says,
unless it treated functions as ‘first-class
citizens’; in other words, the functions
can be used as arguments for other
functions, and be returned as values by
still other functions.
While much of the work in func-
tional programming originated with
academia—Haskell was created in 1990
by academics who were doing much
the same work, but needed a common
language to share their findings—it is
increasingly finding a place in indus-
try. For instance, Google’s MapReduce,
used for searching the Web, draws
heavily on ideas from functional pro-
gramming, Wadler says. Map applies a
function to a large collection of data—
finding instances of a term on scattered
Web pages, say—and reduce then accu-
mulates what it returns, presenting the
search results as a new page.
Facebook uses Haskell to filter spam
from postings. Microsoft supports F#, a
dialect of Ocaml, in its Visual Studio development environment. A functional
language developed by industry, Erlang,
was created by the Stockholm, Sweden-based telecommunications company
Ericsson for telephone systems and
now is used to build scalable real-time
systems for banking, e-commerce, and
instant messaging; the messaging and
Voice-over-IP program Whatsapp is
written in Erlang.
Peyton Jones sees functional programming as a laboratory for trying out new
ideas in programming that then find
their way into other languages. “
Functional programming has been an effective seedbed of ideas,” says Peyton Jones.
“It started off extremely impractical, but
nevertheless intellectually appealing,
and that very practicality forced a series
of ideas to come to the surface that have
then turned out to be useful much more
broadly.” For instance, garbage collection, an automated approach to managing memory, started out in functional
programming but has since been more
widely adopted. It has also been a test-bed for static type checking, which looks
through the program for errors before
runtime and can vastly reduce the number of bugs in a program.
In fact, Peyton Jones says, there is a
lot of work among functional programming researchers on developing richer
type systems, which verify the accuracy
of a program. The theorem prover Coq
is a dependently typed functional language able, because of its type structure, to verify mathematical statements,
though it is difficult to write programs
in, he says.
He sees functional programming
moving toward formal verification, giving developers greater confidence a program will do what it is designed to do.
“The more people care about reliability,
about knowing that something is true,
that money depends on it or people’s
lives depend on it, the more they’re going to care about this,” Peyton Jones says.
Of course, Diatchki says, it is not
only functional programmers who care
that what they write works correctly.
“It’s just that functional programming
seems to be blurring the line between
writing the program and verifying it.”
Peyton Jones believes functional pro-
gramming is becoming more popular as
more developers learn about it. Eventu-
ally, he says, its distinction from impera-
tive languages will all but evaporate, as
the useful features of one approach seep
into the other. “They are kinds of ends
of the spectrum that are converging,” he
says. “When the limestone of imperative
programming has worn away, the gran-
ite of functional programming will be
Diatchki, I.S., Hallgren, T., Jones, M.P.,
Leslie, R., and Tolmach, A.
Writing systems software in a functional
language: An experience report
Antoy, S. and Hanus, M.
Functional Logic Programming, CACM 43,
April 2010, doi: 10.1145/1721654.1721675
Bernardy, J-P., Boespflug, M., Newton, R.,
Peyton Jones, S., and Spiwack, A.
Linear Haskell: Practical linearity in a
higher-order polymorphic language,
Proceedings of the ACM on Programming
Languages 2, 2017
Vazou, N., Choudhury, V., Scott, R.G., Newton,
P.R., Wadler, P., and Jhala, R.
Refinement reflection: Complete verification
Principles of Programming Languages
(POPL), Los Angeles, 8—13 January 2018.
Functional Programming and Haskell
Neil Savage is a science and technology writer based in
Lowell, MA, USA.
© 2018 ACM 0001-0782/18/5 $15.00