One of the blogs [1] I read has been going over the fundamentals of Functional programming lately, and it's gotten me a bit more interested. Then, someone posted a question [2] here that seems like a good fit for recursion/functional programming, which got me thinking about Functional languages again. I'd like to learn one, but now I need to pick one to start learning.
The main Functional languages I hear about are:
I used SML in one of my courses in school, and Lisp in a couple others, but I don't really remember much about them at all. I figure learning any one of them will make picking up the others much easier, so it might not matter too much which language I start with, but maybe there's one that's easier to pick up or more generally useful.
I know F# integrates nicely with the rest of .Net, but I'm don't really use .Net at all (I've done a small amount of C#, but that's it). There's Scala, which integrates with the JVM, but my understanding is that it doesn't support some "functional" constructs like tail-call optimization.
So, I figure I'll ask the cloud. What functional language would you recommend I try learning first? What are the pros and cons of the various options?
I would recommend learning Haskell [1], as it's a pure functional language vs. the mixed paradigm languages you mention. Once you get the concepts in your brain, you can then branch out in whatever direction interests you.
[1] http://www.haskell.org/Haskell [1] is a modern, statically-typed, lazily-evaluated, pure functional language, and I would recommend it for really learning functional programming. Haskell tends to force the programmer to write code in a functional style, since attempting to write code in an imperative style is rather difficult in Haskell.
Note that F# is essentially a .NET implementation of O'Caml and Scheme is a language in the LISP family. JavaScript has some elements of functional style programming, but it is missing a lot. All these languages are open to both functional-style and imperative-style programming, so it is easy to slip back to imperative style instead of really learning to use functional style programming.
[1] http://www.haskell.org/Scheme is by far the simplest. There are many free Scheme interpreters for various platforms out there, and there are many books on Scheme. Check out the course on Structure and Interpretation of Computer Programs [1] on MIT's Opencourseware.
[1] http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/CourseHome/index.htmscheme
out of an xterm
. - new123456
Erlang [1] is a functional language, which is not only functional, but also concurrency oriented. It is supposed to work very efficiently with multicore processors (and that seems to be the future). So if you go with Erlang, you can kill two birds with one stone :)
It does not have the parentheses (that Lisp has) and does not have the lazy evaluation (that Haskell has). But it has all the other "functional stuff", like tail recursion, pattern matching, functions as first class citizens, lambda expressions.
[1] http://erlang.orgI recommend Scala [1] a great programming based on the Java VM. It's a successful mix between imperative and functional programming.
[1] http://www.scala-lang.org/I would say scheme first. And only because say you want to learn a functional language. Scheme has the advantage of an excellent online text book that teaches you not just about scheme but about how to think in a functional language. The book is available here http://mitpress.mit.edu/sicp/.
After you go through the book, it should be much easier to learn whatever functional language you want like Haskell, Common Lisp, F#, etc.. But a functional language is kind of useless if you try to program C/C++ in it. So anyway use the free online textbook to learn Scheme. Then if scheme isn't enough for you go on and learn other ones.
F# [1] is a great functional language.
As I stated here [2]:
[1] http://research.microsoft.com/fsharp/fsharp.aspxF# is a fantastic static-typed functional language with phenomenal type inference eliminating a lot of the code bloat often associated with statically-typed languages. It also has access to the .net libraries which are extensive and very well designed, and being multi-paradigm its flexible enough to allow you to use imperative programming when required. It really is one of the best languages out there at the moment! :-)
I'd recommend Haskell, because it has a nice free interpreter [1], it's lazy, and does type inference for you if you want. It's very nice for a starting language, although I think using GHC [2] you can pretty much do any kind of programs.
[1] http://www.haskell.org/hugs/Definetly Erlang. It's powerful and simple. Might not be the most pretty but most functional languages aren't. Quick to install within 5 minutes you will be writing your hello world.
This is just my opinion but I found it to be the simplest to get started in also.
Haskell's interesting point is it's type system. It has strong typing and can infer types for all functions automatically. And I think it's really easy to get started, see for example a factorial function (the hello world of functional languages ;)
fact 0 = 1
fact n = n * fact (n - 1)
Also there's LISP. I don't know much about it, but from what I've heard, it's a legendary language.
fact n = product [1..n]
. - FUZxxl
OCaml has a very nice balance of functional and imperative features, some decent libraries, and reasonable performance.
I suggest you to take a look at Erlang. I read Programming Erlang - Software for a concurrent world by Joel Armstrong and get hooked with Erlang in the first four chapters.
Good ol' javascript
Check this out [1]
[1] http://www.ibm.com/developerworks/java/library/wa-javascript.htmlScheme is a great start, once you start thinking functionally you can pick up another functional language relatively easy with a bit more effort.
PLT Scheme / Dr. Scheme [1] is a good ide/interpreter/compiler.
[1] http://www.drscheme.org/XSLT is another doorway of insight into functional programming.
While XSLT is arguably not actually a programming language per-se, it certainly provides several of the functional idioms such as variables are immutable after creation, functions/templates cannot have side effects, etc.
I was taught Miranda (for its own sake) as an undergraduate, and it didn't make a lot of sense. Haskell and Miranda are pretty similar, I gather.
Then a term later I was taught Lisp (for the purposes of AI). I think the reason this went so much better was more about the tutor than the language.
When I returned to Miranda, it all made sense in light of what I'd learned about Lisp.
Having said that, if you can find the right educational resource, I feel that a language like Haskell with more syntactical sugar, ought to be easier to learn than Lisp.
A less "pure" answer, and one that lets you play with functional constructs in a very limited way in a familiar environment is to begin by working with the functional constructs in a mostly procedural language (e.g. python).
When I initially ran into this stuff in python I had no idea I'd run into something significant enough to have it's own title, it just seemed like the language supported this cool and elegant way of writing that I'd never seen before (map and lambda constructs, for example). After that lisp didn't seem too alien.
Nemerle [1]
Even though .net/mono, in addition to standard functional stuff it provides some unique concepts like
lisp is nice
I'd suggest you start with programming functional programming in Python. Okay, so it isn't purely functional, but no one is forcing you to utter the word "class" in your code :) You should be looking at inner functions, dynamic scoping, lambda, comprehensions, returning functions as values, and map/filter/reduce. Mainly, try to write code in Python which doesn't spend lots of code writing values to modules or class instances, and is preferably full of lots of nice little functions you can reuse in later projects.
Disadvantages: There are some functional programming concepts which Python simply doesn't have; static type inference and pattern matching being the big ones. You may also find the syntax clunky compared to, say, ML languages. Python isn't that close to the metal, but then you do have the struct and socket and os modules which you can use as necessary. But, Python is a pragmatic choice for many purposes so, with the huge library, you'll actually be able to write lots of code.
I'm afraid I've not read any good literature on functional programming in Python, but it does have most of the useful stuff.
I'm currently learning Haskell to get to grips with functional programming but I'm trying to do a little bit of Erlang on the side. From reading the previous answers my experience seems to be fairly typical:
I too read Programming Erlang by Joe Armstrong and fell in love with it. But from this I learned about Haskell. I have decided to stick to learning Haskell to get my brain used to doing functional programming and then I'm going to move onto Erlang - which is where I want to end up ulitmately.
I don't think there's any harm in dipping into other functional languages just to have a play around. I've already ordered a book on Clojure and I'm thinking of ordering an F# one as well (If someone can recommend one i'd be greatful).
I still can't believe that not one person mentioned about Lua [1]. This language has really simple syntax, gets the basics right and it is functional at core. Executes really fast whatever you throw on it.
Also it has everything you need to get you into the OOP path later on. Good range of modules and a really helpful community. Those sum it up for Lua [2].
[1] http://www.lua.orgC++, Smalltalk, and python.
That's right - you can use functional programming techniques in all of those languages.
I wouldn't recommend them as your only functional programming languages, because using languages focused on functional programming helps inform taste. In the end the choice between FP-oriented languages is minimal if you just want to learn. Common lisp is the least clean, though.