You are on page 1of 2

Is functional programming moving away from linked lists?

https://qr.ae/TWNRPi

Bruce Richardson, Professional experience with Assembler, C, XSLT, Scala and much else.
Updated Jun 11

There’s a whole range of contexts where lists have ceded ground to more appropriate abstractions.

In Haskell:

 Lists have steadily been deprecated as the default iterable in libraries. With a lot of legacy
code, this has been a slow process, but Foldable Traversable In Prelude succeeded, while
other aspects of the Burning Bridges proposal are still being carefully steered.
 One of the worst warts from the “lists for everything” days - Strings as lists of Chars - has
long been deprecated as common practice and the Overloaded strings extension is there
to help.
 Lists for IO streaming and stream processing have been widely recognised as a bad
idea. Pipes, Conduits and iteratees give much more control and flexibility (although a lot of
people are still trying to get their heads around iteratees).
 Sequences are better for where you want to work in constant space but need to keep N
(where N is small) elements and manipulate the queue as you go.
 Vectors are better for a range of use cases.
 Pattern synonyms and view patterns make these other data structures as fluent to work
with as lists.
Some of those points are valid for other FPLs. Iteratees have gained some traction in Scala, for
example, Vectors even more.

One important concept that has made data structures other than lists easier to navigate in a generic
fashion is Zippers.

Generally in the FP world, as Corecursion has become more widely understood, the understanding
has spread: lists are not the only abstraction that can be handled lazily and iteratively in constant
space.

Clojure dethroned the linked list in favour of Sequences, an abstraction for which the linked list is
just one possible implementation. Clojure’s syntax, encouraging the use of things other than
parentheses, deliberately reinforces the idea that not everything is a list. Clojure, being one man’s
innovative project rather than a “best of breed” derived from consensus, has been successful from
the start in something that the Haskell community is still only slowly approaching. (Haskell’s journey
there is made harder by not having a more sophisticated module system like SML/OCaml)

Pedagogy loves linked lists because they are easy to explain. As a result, getting new developers to
understand that not everything is a list can be a slog. If students are lucky enough to learn from
somebody like Philip Wadler or Conor McBride, they’ll be getting a richer story. Hopefully, advances
in industry practice will eventually feed back into wider education.
Linked lists are not going to disappear, but other abstractions have taken a lot of their old ground
and will continue to do so. It’s important that story is told.

You might also like