can Python be useful as functional?

Kay Schluehr kay.schluehr at
Tue Sep 18 11:13:49 CEST 2007

On 18 Sep., 10:13, Bruno Desthuilliers <bruno.
42.desthuilli... at> wrote:
> Lorenzo Stella a écrit :
> > Hi all,
> > I haven't experienced functional programming very much, but now I'm
> > trying to learn Haskell and I've learned that: 1) in functional
> > programming LISTS are fundmental;
> Not exactly. They are used quite a lot, yes, but that's also the case in
> other paradigms. What's important in functional programming is *functions*.

Functional lists are not quite the same. They are actually recursive
datastructes. In Python you would model them as nested tuples:

t = (a, (b, (c, ...(d, None)))))

These are essentially pairs build from the bottom up using a list
constructor and they have little in common with those mutable list
objects ( arrays, vectors ) being used in Python. You can easily
extend them into n-ary trees and implement mutations on them as forks
where the original strucure is almost preserved. This leads to all
kinds of "functional data structures".

In order to access an element you already need a recursive function
defintion ( unless you just want to examine the head or the tail
only ) and this makes functional programming and "consed" lists a
perfect match.


> Strictly speaking, a language is functional if it has functions as first
> class objects. Period.

No, not period and not strictly speaking. A language is functional
when its semantics is based on lambda calculus where everything is a
function or a variable bound to a function which can be substituted by
a function. Each functional language, to be usefull, must be augmented
with programming language constructs used from other paradigms or
support unsafe operations to enable proper side effects. This is not a
humpty-dumpty issue where everyone can name his language a functional
programming language just because one can pass functions as first
class citizens around and he says so. Otherwise those languages can
support a few functional programming language idioms such as map,
reduce and filter or comprehensions as in Pythons case.

More information about the Python-list mailing list