views:

1378

answers:

8

I've recently been dabbling in functional programming with languages like Lua, Scheme and most notably F# and there are a lot of resources to learn these languages. However, the resources that I've found and have been using essentially teach only the syntax of these languages. While that's important, I can do this in a day or two. I just don't feel I'm using these languages as intended as I'm largely treating them as imperative languages (where possible).

Can you recommend any resources that teach functional programming, rather than "Learning [insert language]"? My biggest interest is in parallel processing, but I'd like to take it one step at a time.

+3  A: 

I would try to check out SICP. It is an introductory course taught at many Universities that uses Scheme as its language of choice.

The first big step is understanding powerful functions like map and fold. Pattern Matching where the language allows it also. Things should come much more naturally afterwards.

Nicholas Mancuso
+1  A: 

I have heard good things of The Haskell School of Expression, SICP, and The Little Schemer.

rz
The Little Schemer is a great book, Makes it fun to learn Scheme
Shiv
+1  A: 

For F#, IMHO, the best book is Expert F#. However based on your initial comment I'm going to guess that it won't go deep enough into the functional style of things.

Right now the absolute best source for good F# advice and programming is the blogosphere. The F# team and all many powerusers/ethusiast are active bloggers. Since this is a relatively new language, many of these blogs are focused on explaining exactly what F# is and how it's meant to be used.

In particular I would read these blogs. I would start off with the first 2 listed. Go back in time and go through their articles in chronological order. If you have a solid basis in C#, look at many of the earlier entries the first listing. He does several intro C# -> F# pieces.

  1. http://lorgonblog.spaces.live.com/blog/fakehandlerpage.aspx?wa=wsignin1.0&sa=733042901
  2. http://blogs.msdn.com/chrsmith/
  3. http://blogs.msdn.com/dsyme/
JaredPar
+12  A: 

I teach functional programming regularly, and I wish I knew of better resources. Here are a few suggestions, mostly aimed at programmers with some programming experience.

It's only about data structures, but Chris Okasaki's Purely Functional Data Structures is pretty amazing and will definitely prevent you from treating anything as imperative. I also hear good things about Graham Hutton's book for beginners using Haskell, but I can't say anything about it of my own knowledge. I second the recommendation of the Haskell School of Expression.

My other thought is that SICP is not a good book from which to learn functional programming. If you already know Scheme, it is a good book to admire, but SICP is less about functional programming and more about how to implement all known interesting computer-science ideas in Scheme. Two techniques that are very important to many functional programmers---programming with pattern matching and partial application of curried functions---are not well supported in Scheme, and you would be missing out on a lot of the promise of languages like F#. On the other hand, Lua, being very similar to Scheme, doesn't support these things either.

Try Haskell; Haskell makes it a lot harder for you to program your old thoughts in the new language. Instead, Haskell forces you to think new thoughts.

Norman Ramsey
+3  A: 

If you are considering learning Haskell I'd take a look at Real World Haskell. It is a good introduction to the language, with examples related to real-world problems (like using databases, web client programming, etc). It has recently started shipping, but it's also available for free from here.

Magnus
+1  A: 

You have to write a whole bunch of functional code before you learn to think like functional programming languages do. I recommend choosing a functional language that interests you and tackling some simple problem sets in the style of Project Euler.

Once you've begun to think like a functional program does, you can start pressing into more and more complex applications of FP.

sblom
+1  A: 

When I was in school, we had a course called 'Programming Paradigms' where we learned about functional,logic,and imperative. What really helped me was that we were given the same problem for all three. It was a high level graph related problem, I think something to do with shortest path calculations. Solving the problem in all three language types helped me learn a great deal. What I would suggest is the same as sblom, find some general programming problems from around the web, and starting solving them using a functional language.

nstehr
+1  A: 

I'm sure it's been mentioned elsewhere, but I think Learn you a Haskell for a great good does an excellent job of gently introducing functional concepts without requiring you to understand esoteric mathematical notation.

Okasaki's book is really excellent, but you'll have to commit more to understanding it unless you already think in typed lambda calculus.

JasonTrue