views:

1681

answers:

17

What would you recommend for an experienced OO programmer who wants to learn more about functional programming?

Since reading Mark Dominus's Higher Order Perl, I've begun using more functional techniques in my day-to-day work, such as closures, currying, and lazy evaluation. However, Perl is of course not a purely functional language (it's not purely anything) and I'm curious to learn how functional languages like Haskell accomplish common tasks. However, the last time I tried to learn Haskell via a few web tutorials, I found its rather terse syntax intimidating (and I'm a Perl guy.) Do you have any recommendations for a gentler introduction to Haskell or FP in general, and what are the advantages and disadvantages of other functional systems like Lisp, Erlang and F#?

+6  A: 

Yes, standard ML, try SML/NJ. The go to the Project Euler, and start solving problems in SML. There are several well-written tutorials for SML, they're easy to find if you look for them.

zvrba
+1  A: 

I'd suggest UC Berkeley's podcasts on programming, findable on iTunes University as a start.

warren
+2  A: 

If purely functional languages are a hard pill to swallow, try another non-exactly-functional language. Lots of people like Python for this. Personally, i found that after mastering Lua i could finally grok Scheme.

Javier
+2  A: 

I found Haskell much easier to wield after a tour through SML, which is a smaller (strict, impure) functional language. SML's typesystem doesn't have typeclasses, and writes pairs in a more mathematical way, but otherwise is very similar. Once you can distinguish runnable code from type declarations (it may be confusing to beginners that they are in two different namespaces, despite showing up interleaved in source code), you should be able to start reading real working code and learn quickly.

ephemient
+3  A: 

I've been trying to get a grasp of F# recently and I've found that tackling the Project Euler problems has helped me get a good handle on the basics as most the tasks are very well suited to be solved in a functional style.

Garry Shutler
+2  A: 

For learning Haskell you could take a look at Learning Haskell. They have some tutorials and links to text books. It should get you started with Haskell and the different implementations.

Another idea is to take a look at Helium. It's an implementation of Haskell, especially developed for learning Haskell. It is used at Universiteit Utrecht for the courses Functional Programming. The main idea is that the compiler gives you better error messages and hints for how to fix the compile problem. The main Haskell compiler, GHC, suffers from inexplainable error messages. They have been using it since 2002 or so, and had a lot of feedback from students.

Michiel Overeem
A: 

Mark-Jason Dominus is going to be pissed when finds out Damian Conway stole his book!

Dave Rolsky
... and his website.
Brad Gilbert
Doh! Nice catch. Updated the question to correct the error.
friedo
+1  A: 

Well, you could play around with using functional features in Smalltalk, which is OO. Common lisp is not purely functional in any sense (which is not to say it is bad). You could try Scheme, which is a member of the lisp family, and like (almost) all lisps is late bound with no type declarations for variables, which is likely to be more up your street.

Something like Haskell or SML will be interesting because they are strongly (statically) typed, but avoid type declarations for the most part. Haskell is also lazy, but manages to be completely early bound as well. I would recommend playing around with it more (although I also can't manage to get it to work properly with all the type declarations and files).

Marcin
+7  A: 

You should read the book Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman. It is about functional programming (with SCHEME) in detail and does a very good job at explaining the paradigms of functional programming, as well as the ideas behind it.

And, the book is available online for free.

ypnos
SICP is far too out of date to be useful: it predates all modern type theory and most of the code in that book is in an awful (typeless) style from the point of view of any of the popular functional languages (F#, OCaml and Haskell).
Jon Harrop
+11  A: 

I would recommand this one:Real World Haskell.

I'm a newbie of Haskell, I found this book is really good to read and it tells you the basic concept of functional programming and haskell, and how could you use them to solve real world problem.

Even I didn't know what is functional programming or learned haskell before, I could understand most code example in that book, since it explained very clearly.

I believe it is one of the best tutorial on the web, and really excited when I found it because I never understand what and how a purely functional programming can be used in real world application.

Brian Hsu
I've been working through RWH and can only say +1 on this.
Charlie Martin
+1  A: 

Here's some things i liked:

http://web.archive.org/web/20041012103936/http%3a//www.bagley.org/~doug/ocaml/Notes/okoans.shtml

the list of papers by Hudak, Jones, and others in this thread is a good start point

http://www.reddit.com/info/6pqa6/comments/

this graphic: may not help, but might!

http://www.info.ucl.ac.be/~pvr/paradigmsDIAGRAMeng107.pdf

Gene T
+3  A: 

Rich Hickey has provided some great videos introducing the Clojure language to Java programmers...

johnstok
Except that Clojure is arguably not functional because it lacks tail calls.
Jon Harrop
+1  A: 

Read this: http://www.defmacro.org/ramblings/fp.html I was in the same boat - a reasonably good oop programmer, was interested in FP but the ideas and limitations (well, they seemed like it at the time) gave me quite a few "wtf" moments. This explanation cleared it up and really got me stoked on the idea of learning a FP language.

hydo
A: 

I enjoyed The Little Schemer and it's continuations (ha) as introductions to functional programming. Less dense, playful, question-answer style. Depending on how well you grok FP the little schemer might be slow at first, though.

lucas
A: 

Gerald Sussman's Structure and Interpretation of Computer Programs Lectures: Videos

Dylan White
+2  A: 

I have had a hard time "groking" the Functional Programming Paradigm as well. The following books, however, have really helped my understanding:

The Little Schemer

Amazon.com Review This delightful book leads you through the basic elements of programming in Scheme (a Lisp dialect) via a series of dialogues with well-chosen questions and exercises. Besides teaching Scheme, The Little Schemer teaches the reader how to think about computation. The authors focus on ten essential concepts of thinking about how to compute and demonstrate how to apply these concepts in inventive ways. The Little Schemer is an excellent book both for the beginner and for the seasoned programmer.

The Seasoned Schemer

Amazon.com Review

Friedman and Felleisen's The Seasoned Schemer picks up where their book, The Little Schemer, left off and focuses on the myriad uses of functions in Scheme. Using the same dialogue format as The Little Schemer, the authors demonstrate how Scheme's flexible facilities for handling functions give the program so much variety and power. Along the way, the authors also present a variety of other more sophisticated language constructs.

Essentially, my strategy was to work through the exercises in these books and apply the "rules" each of them espouse to the particular language I was learning.

+1  A: 

I'll second "Real World Haskell". Its been a great help. Also, find a copy of "Haskell: The Craft of Functional Programming" This was the text we using when I was introduced to Haskell in college and a great reference.

unclerojelio