Functional Programming Language

A Programming Language is called functional if it supports and/or encourages Functional Programming. Dysfunctional otherwise. *Arr arr arr*

A list of Functional Programming Language descriptions and links:

Haskell [Haskell Language] - the archetypal FPL in the 1990s, it is lazily evaluated (as opposed to strictly or eagerly evaluated, see Lazy Evaluation), Statically Typed and supports input/output, GUIs, animation, databases, COM and ActiveX, etc. I.e. all the usual "side effects" that are not usually considered to be practical in functional programming are practical in Haskell with Referential Transparency (See On Monads). There are several open source systems. See also Template Haskell.

Erlang [Erlang Language] - the champion FPL in the 1990s, it is Dynamically Typed, mostly functional (i.e. supports some imperative side effects that break Referential Transparency). Erlang applications are composed from Communicating Sequential Processes (shared nothing message passing). This is the champion FPL for the 1990s because was developed by Ericsson and is used in several released products (switches, etc.) for soft real time distributed telecommunications. There is one open source system that includes a CORBA ORB, Naming service, Event service, a distributed soft real time database with nested transactions, replication, and a query language, among other goodies like SNMP, HTTP, etc.

ML [Ml Language] e.g., SML [Standard ML, Sml Language], SML/NJ, CAML, CAML-light, Objective Caml, Alice Language, Fsharp Language, etc. Statically typed, eagerly evaluated, etc. Interesting ways of combining source code based on "functors" (basically, mappings from collections of functions to collections of functions).

Common Lisp (and others)-- though impurely, and as only one of the many paradigms supported

Scheme [Scheme Language] (and variants)-- though impurely, and as only one of the many paradigms supported

m4 (the macro processor), which is available in almost any Unix Like environment, is largely functional even though it supports imperative features. It has an exotic Level Of Quoting concept, and allows all kinds of quirks by being ultimately text-based. Implementations often have undocumented limitations which causes your macro expansion to fail in spectacularly bamboozling ways.

FP - an interesting twist on functional languages -- no variables! You write programs by composing functions into new functions. Mostly a proof-of-concept language, little real use, but interesting to play with. It is described in John Backus' ACM Turing Award Lecture "Can Programming Be Liberated From The Von Neumann Style" (1977). This is the functional language that made functional programming an (academically) household name. Succeeded by FL.

FL - As with FP in nearly every respect, it remained a research vehicle at IBM, ultimately providing a foundation on which Iverson's Apl Language and Jay Language builds on.

Cindy Script the functional scripting language of Cinderella

Clojure [Clojure Language] A lisp variant that emphasizes functional programming more than other dialects (and more than other paradigms).

Miranda [Miranda Language] - a language designed during the 80's that was a precursor to Haskell, using a very similar syntax. (A short introduction is at blackcat.brynmawr.edu ).

Joy [Joy Language] - a purely functional language based on the composition of functions

Nemerle [Nemerle Language] - an OO/functional language for the Common Language Infrastructure with hygienic code generating macros, algebraic datatypes and matching, higher order functions, lexical closures, and partial type inference (types are only inferred within methods, in order to avoid accidental changes to class interfaces). Syntax is superficially similar to C#, but the language is semantically more similar to Ml Language and descendants.

Mercury - The Mercury Language is a new logic/functional programming language, which combines the clarity and expressiveness of declarative programming with advanced static analysis and error detection features. Its highly optimized execution algorithm delivers efficiency far in excess of existing logic programming systems, and close to conventional programming systems. Mercury addresses the problems of large-scale program development, allowing modularity, separate compilation, and numerous optimization/time trade-offs.

Pure [Pure Language] - Term-rewriting language. code.google.com

The Un Lambda Language has only functions. (But it's probably of theoretical interest only.) It's an Esoteric Programming Language.

There is also another (purer) functional Esoteric Programming Language:
Lazy-K.

Dylan [Dylan Language] -- allows functional programming style, but also imperative/o-o style

Needle [Needle Language] -- similar to Dylan, but leans more towards the statically-typed side

Goo [Goo Language] -- Scheme with some concepts (notable Generic Functions) borrowed from Dylan.

Mathematica [Mathematica Language] -- the crux of the Mathematica Package produced by Wolfram Research

XSLT [Xslt Language] -- "The Functional Programming Language XSLT - A proof through examples" www.topxml.com

Ruby [Ruby Language] -- pretty mix of functional and object oriented

Pick language and derivatives - Open Insight, Advanced Revelation, Universe, Unidata, Maverick, Jbase and many others.


What are the criteria for inclusion above?

There will be different opinions. I would include any language that encourages a functional style of programming. So ML and Common Lisp and Scheme could be in this list.

What about Lisp? Too old? Too many side effects? Too many dialects?

Each Lisp should be listed on its own since they are so different especially in how they encourage functional programming. Clojure is the most "functional purist" of them, followed by Scheme and Common Lisp (in that order), which like to think of themselves as being multi-paradigm.

What about Pizza? Too young? Too short-lived? Too close to Java?

I would include Pizza since it extends Java by adding first-class functions, and so encourages a functional style of programming. Much more so than the anonymous classes of Java.

What about Prolog? Too old, too academic?

You cannot define a function in the Prolog Language, or apply a function to its arguments. Prolog is not about functions, it is about predicates; it is a Logic Programming Language. However, both Erlang and Mercury were developed from Prolog.

What about Python Language?...

Guido seems to have spent a lot of breath convincing us that Python is not a functional programming language. Guido even wanted to remove lambdas; however, public outcry ultimately forced him to keep lambdas in the language.

Guido wanted to remove lambdas in the belief that named functions are easier to read, not out of any particular dislike for functional programming. Python contains functional features adopted from many other languages, such as Haskell's list comprehensions and LISP's map/filter/reduce (= Haskell foldl). Use of first-class functions is common in the standard library's API.


There is some discussion about the relative advantages and disadvantages of Functional Programming and Object Oriented Programming and about the degree that Functional Programming and Object Oriented Programming can be used in the same language. See Fp Vs Oo, Oo Vs Functional, Closures And Objects Are Equivalent.


What about Cee Omega and C# 3.0? They have a hybrid mix of imperative and functional paradigms.

Those are basically vaporware at the moment, aren't they? If so, then who knows what directions they may take in the future.



Most newer Functional Programming Languages support static type-checking, so if you have a function f of type A->B i.e. f takes an arg of type A and returns a result of type B, and an expression x of type A then you can apply f to x to get something of type B. Since functions are first class citizens the x could it self be a function. E.g. suppose I want a function dot which takes two functions and returns a function which applies the second fn then the first fn , its type would be:-

dot ::
(b -> c) -> (a -> b) -> (a -> c)

(using Haskell syntax - x :: T means x is of type T. Identifiers in types starting with lower case are Type Variables and denote arbitrary type. That is called Parametric Polymorphism). It could be defined as:-

dot f g = \x -> f (g x)

(The "\x -> .." part is an Anonymous Function.) This would be another way of defining dot:-

dot f g x = f (g x)

(The dot function is actually defined as an infix "." operator in Haskell Language) Another example is the curry function from the Haskell prelude :-

curry ::
((a,b) -> c) -> (a -> b -> c)

curry f x y = f (x,y)

i.e. it takes a function which takes it arguments as a pair and returns an equivalent function which takes it arguments in a curried form. (See Currying Schonfinkelling.)

Hence functions can be manipulated in a quite sophisticated fashion. Try to do this in C++/Java and you will probably have to write an FP interpreter. -- Jon Hanson

I wonder if you could write an Fp Interpreter Using Templates?


To do I/O in Clean in a functional way, you pass the world around, and compute new values of the world. Because Clean has Unique Types, the Clean compiler can guarantee that there is always only one live copy of the world around. Therefore, it can mutate the world in-place, rather than having to copy it entirely, which would be computationally costly, to say the least. ;-)

Haskell doesn't have Unique Types, so it cannot take this approach. Therefore it uses monads.

This is a subject of Holy Wars, but I prefer using monads to Unique Types. Monads are at least native functional constructs and don't need specific language support. Besides, you get rid of the explicit passing of world - which has no benefit anyway, because you can't copy the world.

Unique Types aren't used just for IO, other uses include arrays with destructive updating. Also Unique Types are easier to use when you want to write code that has two kinds of effects (e.g. read a file and put the contents in an imperative array). In Clean you can freely mix the two kinds of Unique Types where in Haskell you need to write some specific monad transformer to let you mix IO and State monads. Also you can have monads (modulo syntatic sugar like Do Notation) in Clean, but the inverse isn't possible in Haskell. Saying that Unique Types can be very hard to grok.


I've been peeking at J, from www.jsoftware.com , and see the ad phrase that says "OOP is easy with J4!". But reading the documentation, I can't see that "locales" can be constructed as variables, so I can't see how to implement polymorphism or inheritance. Anyone got a clue? --Alistair Cockburn, 7/99

[I believe the "J4 makes OOP easy!" statement was some part fluff, in response, after OO abilities were added, to many previous "Does J do OOP?" questions.]

It doesn't look OO at all to me, it looks like Backus's FP revived. Where does it say that OOP is easy with J4? I think I am too old to decipher line noise any more. --John Farrell

It says, "J4 makes OOP easy! New language extensions include hierarchical paths and object locales that can be dynamically created and referenced. The underlying primitives allow you to follow the OOP model exactly. The new facilities are of general applicability, and so powerful and easy to use that they should dramatically improve the way we build systems in J. " from the j download page.

www.jsoftware.com ? Maybe the page has changed. The site now talks about J403. [J4 refers to all releases numbered J4xx; J403 is the 3rd revision of J4.]

I don't recall anything that I would consider object-oriented in J, though I don't consider that a problem. The locales seemed to be more a module or namespace feature. -- Ward Cunningham

The documentation for some recent features (OO, sparse arrays, memory mapped nouns) has not made it to the manuals and help files. Instead, Lab session scripts (which provide interactive tutorials) are included, but they are not fully meaningful outside of a J Session. J's OO abilities are implemented using locales. It's worth downloading a trial copy just to go through the labs. -- Jim Russell

Don't know if it's of any help, but I've been playing with a simple OOP example in a number of different languages - mostly for recreational reasons ( see w3.one.net ). I've completed the example for the J language (as well as a couple of others) which can be found at www.angelfire.com . -- Chris Rathman

[2001/08] A HTML Manual is installed together with the software, which is more up-do-date than the PDFs on the download page. In the manual for the free edition for windows I found a chapter on OOP. Its path is \system\extras\help\learning\25.htm


[C++]

You can get currying in native Cee Plus Plus using Templates. And a form of lambda functions are also possible. See


[PHP]

PHP programmers may want to check out this library that adds some functional programming abilities to PHP4. See


[Aleph Language] (See www.aleph-lang.org ). From the website:

"Aleph is a multi-threaded functional programming language with dynamic symbol bindings that support the object oriented paradigm. Aleph features a state of the art runtime engine that supports both 32 and 64 bits platforms. Aleph comes with a rich set of libraries that are designed to be platform independent"

The last release is from mid-2001 but the language is kinda interesting, and the compiler is really cool (written in C++, it compiled without errors on gcc 2.96.x and just two unprotected #define's in a couple of header files in gcc-3.2. No warnings.

It's a shame they don't seem to be developing/supporting it further. Maybe it can be saved if we manage to get a community effort (licenses providing, the compiler was Free Software).

(Update: I have managed to get in touch with Aleph author, Amaury Darsch, and he's indeed silently working on version 0.9.0, with updates on the web site coming soon. Joy!)



20081106 -- Chris Garrod asks would it be ok to alphebetize the languages on this page?

That would be reasonable, but I would consider ensuring there is a list naming the most 'mainstream' FPLs at the top (Haskell, ML, Erlang). Other orders that are okay would be order of creation.


April 2010 What kind of programs do you think are written more easily in FP languages? Specifically for people who use FP and non-FP languages - what situations do you find yourself using FP languages for? For example, I'm an aspring academic. Are they especially suited to mathematical and/or logical thinking? Number crunching?


Is Lua Language a functional programming language? I was just debating this with someone who claims it is not. But if not, what disqualifies it (that does not also disqualify Scheme Language?)



See original on c2.com