A ProgrammingLanguage is called functional if it supports and/or encourages FunctionalProgramming. Dysfunctional otherwise. *Arr arr arr*
A list of FunctionalProgrammingLanguage descriptions and links:
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 CommonLisp 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 PrologLanguage, or apply a function to its arguments. Prolog is not about functions, it is about predicates; it is a LogicProgrammingLanguage. However, both Erlang and Mercury were developed from Prolog.
What about PythonLanguage?...
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 FunctionalProgramming and ObjectOrientedProgramming and about the degree that FunctionalProgramming and ObjectOrientedProgramming can be used in the same language. See FpVsOo, OoVsFunctional, ClosuresAndObjectsAreEquivalent.
What about CeeOmega 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 FunctionalProgrammingLanguages 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 TypeVariable?s and denote arbitrary type. That is called ParametricPolymorphism). It could be defined as:-
dot f g = \x -> f (g x)(The "\x -> .." part is an AnonymousFunction.) 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 HaskellLanguage) 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 CurryingSchonfinkelling.)
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. -- JonHanson?
I wonder if you could write an FpInterpreterUsingTemplates?
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 UniqueTypes, 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 UniqueTypes, so it cannot take this approach. Therefore it uses monads.
This is a subject of HolyWars, but I prefer using monads to UniqueTypes. 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.
UniqueTypes aren't used just for IO, other uses include arrays with destructive updating. Also UniqueTypes 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 UniqueTypes 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 DoNotation) in Clean, but the inverse isn't possible in Haskell. Saying that UniqueTypes can be very hard to grok.
I've been peeking at J, from http://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? --AlistairCockburn, 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. --JohnFarrell
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.
http://www.jsoftware.com/download/download.htm ? 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. -- WardCunningham
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. -- JimRussell
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 http://w3.one.net/~jweirich/oostuff/ ). I've completed the example for the J language (as well as a couple of others) which can be found at http://www.angelfire.com/tx4/cus/shapes/index.html . -- ChrisRathman
[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 <j406d_root_folder>\system\extras\help\learning\25.htm
http://www.jsoftware.com/download/download.htm
[C++]
You can get currying in native CeePlusPlus 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
[AlephLanguage] (See http://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 FreeSoftware).
ChristophePoucet? asks WhichFunctionalLanguageToLearn.
20081106 -- ChrisGarrod 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? --JasonEspinosa
Is LuaLanguage 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 SchemeLanguage?)
WhyFunctionalProgrammingLanguagesArentMainstream