views:

1915

answers:

17

I'm looking for some ebooks that will assist in my learning of functional programming. I haven't yet decided which language I will go with, but I've noticed a fair amount of bias towards LISP, Haskell and F# amongst the community on StackOverflow. As yet, I'm unsure which direction I will take, but can anyone recommend any particular eBooks on the subject? In addition, if anyone could present a compelling argument for which functional language would be the most interesting pursue, I would be most interested to hear your opinions.

I'm particularly interested in eBooks because I managed to score myself a Sony eBook Reader for Christmas and I'm looking to load it up with useful material for my never ending quest to become a better programmer.

TIA

+19  A: 

I just started following the Structure and Interpretation of Computer Programs video lectures, and I think they're wonderful. They adopt Scheme, which is a variant of LISP, as the programming language. But that's not the point of the course: It is about the whole concept of "computing" and its implications.

Federico Ramponi
I second the recommend of SICP.
A. Rex
SICP/Scheme is great, but it does several things that go against the grain of functional programming, in particular by being untyped and encouraging a lack of distinction between code and data. It has a philosophy of its own, but it's not FP. Still, it's better than Common Lisp. http://is.gd/fmxu
ShreevatsaR
+32  A: 

I recommend Haskell. Please check out these (online and print) book recommendations in another SO question.

Reasons in favor of Haskell:

  • From a personal perspective first: I spent a considerable amount of my early programming years thinking about designing my own programming language. (For example, I highly recommend the textbook Programming Language Pragmatics.) When I first encountered Haskell, I realized that it incorporated many of the ideas I had, plus many more, and all in ways far better than I could have done myself.
  • It's a very pure implementation of functional ideals: lazy (non-strict) and (polymorphically) statically typed. No side effects!
  • Its type system might change your view of type systems. (Hindley-Milner type inference is amazing.)
  • Its alternative view of object-oriented programming and polymorphism is great.

Lisp is also a good choice. Reasons in favor of a Lisp variant:

  • Historically the first functional programming language (or the first huge one).
  • The worldview "everything is a list" is very minimalist, simple, and beautiful.

If you do choose a Lisp variant, I recommend Scheme.

I have not used OCaml or Ruby, but some of my friends swear by them, though one could argue how functional they are. On the other hand, their "multi-paradigm" nature makes them very convenient in practice.

To conclude, I suggest you choose a language following Alan Perlis's advice: "A language that doesn't affect the way you think about programming, is not worth knowing." Lisp and Haskell both changed my world. I hope that no matter what language you choose, it changes your world.

A. Rex
I don't think Haskell is a good language to start functional programming, it's very extreme, you cannot gently transition from procedural to functional code like you could in Scheme, Common Lisp, or even Ocaml.
taw
Point taken. However, I think it's worth the effort.
A. Rex
+1 for the recommendation to learn a language that affects the way we think about programming. I agree that the point in learning a new language is to affect and extend our view of programming.
BobTheBuilder
I love Ruby, but I'd say it's a poor choice for the functional paradigm. There's actually an active thread on the mailing list about this now
J Cooper
Aforementioned thread: http://www.ruby-forum.com/topic/175136
J Cooper
I don't think for many people a gentle transition will work. Learn FP in a language that forces you to use FP. Later, if you want to, go and apply those skills in Ruby or whatever.
slim
@J Cooper and @slim: I definitely agree. This is why I support Perlis's approach of "go out there, learn a new language, change the way you think about programming, come back, apply it". It's also why SICP is a good course, even though hardly enough writes Scheme. That's not the point.
A. Rex
I'd recommend Haskell everyday of the week and twice on sundays.
Rayne
I also don't think Haskell is a good functional language to start with. You'll just end up learning a long list of workarounds for the lack of side effects that are academically interesting but totally useless in the real world.
Jon Harrop
+2  A: 

I might get downvoted for it but I say go for Ruby. It's a very nice and modern hybrid functional-OO language, and it will gently introduce you to the world of functional programming. Or any other language with closures and high order functions (it has to be either dynamically typed or with type inference, otherwise it's really hard to write functional code).

Once you're comfortable with Ruby FP, or if you don't want to listen to my best advice, try something like Scheme. It's an elegant and gentle language.

If you start with Common Lisp or Ocaml or Erlang or especially Haskell you will most likely get scared and you will feel lost, for different reasons. If you're comfortable with Scheme, you might want to try these, but I would really advice against starting with them. Few people go far this way.

taw
What makes Ruby so compelling? The softly softly approach never really did it for me. I'm more of a "let's bust the VCR into a million pieces and try and put it back together" kind of guy. Ok, I was only 11 when I did this and I got grounded, but I did manage to put it all back together.
BobTheBuilder
See my comment on A. Rex's answer
J Cooper
Ruby is compelling because it's very usable language for many things (for web programming currently the best) even if you don't know any functional programming, so you can solve real problems and see how functional patterns can help with real stuff. In Haskell you'll most likely write hello worlds.
taw
I can't see Ruby being a great tool for learning FP. Since it gives the opportunity to use 'traditional' methods, most people will stick to what they know. Learning in Haskell forces you to use FP for everything. There are plenty of exercises in Real World Haskell way beyond Hello World.
slim
Re writing hello worlds: I can understand this fear. However, when I learned Haskell, I immediately wrote something useful, a parser for a document format I was working on. I very successfully used Haskell's features to write a useful program. (Note: I do admit Ruby is useful on the web.)
A. Rex
I agree wth slim, using a purely FP language forces you to use FP constructs such as recursion and not fall back on other traditional programming methods and hence keeps you in line. Ruby would not be a good choice.
Deep Kapadia
This is getting into learning approach issue. I would strongly recommend gentle introduction of concepts into context of what is already familiar, you want to learn swimming by jumping from a ship in the middle of the ocean. If you want gentle go Ruby/Scheme, if you want extreme go Haskell/Erlang.
taw
In Ruby, methods are not really first class members.
pi
+7  A: 

I'm in the the middle of reading Yet Another Haskell Tutorial and it's a very helpful and well written Haskell book.

vili
+5  A: 

Practical, Common Lisp is a fantastic ebook if you're interesting in diving into Lisp. It is quite different than many languages out there, but I felt like pushing myself to learn it was one of the most rewarding experiences in my programming career. The limited syntax makes for a highly flexible language that is relatively easy to learn, but conceptually it will take some time to wrap your mind around.

HappyCodeMonkey
+4  A: 

I would recommend any of the ML (Standard ML or OCaml are good) dialects for a language.

They had a huge influence on Haskell and are a somewhat gentler introduction to FP than Haskell.

+1  A: 

"How to Design Programs": http://www.htdp.org/

By the way, what are your goals?

grettke
+3  A: 

I hop you chose Erlang or Lisp. (Forth) There you have the most mindbending languages I know.

Where should I go after Erlang, Lisp and Forth, please leave a comment.

Flinkman
+1  A: 

I am in no way an expert on this, but personally I think starting with scheme might be a good idea. From what I know, scheme is a simplified version of LISP, think of it as LISP but with only the bare essentials. I think the syntax of scheme is extremely pure, you have to get past the parentheses but it really helped me get into the 'feel' of functional programming, without having to learn gobs of language features.

Mongoose
+1  A: 

I would start with Lisp (specifically Scheme) because it is simple; it has a very simple Syntax and no static type system to worry about.

Structure and Interpretation of Computer Programs will not only introduce you to Scheme but teach you all the major programming paradigms. The full text is available under a Creative Commons license.

After that you will have an easier time learning the additional features of Haskell, i.e. a more elaborate syntax, lazy evaluation and a powerful type system.

starblue
+7  A: 

Obviously, it depends.

Are you familiar with C#, and .Net framework? If so that'll give you a kick start using F#. If you've got Visual Studio, you can play around with F# too, so that's another learning curve flattened.

It also depends whether you're just looking to 'grok' functional programming to widen your horizons, or actually use it some time. If you're just groking, then start anywhere, but if you intend to use it, then choose something which is compatible with your current framework.

My 2 cents/pence

Benjol
+1  A: 

Two great books:

"Structure and Interpretation of Computer Programs" (by Abelson & Sussman) and "Concepts, Techniques, and Models of Computer Programming" (by Peter Van Roy and Seif Haridi).

Both cover much more than functional programming only.

blabla999
+5  A: 

Maybe one option is to pull down the entire online version of Real World Haskell?

It's a good book for learning Haskell, but arguably it might need to be paired with a more general book on functional programming.

Magnus
+1  A: 

I'll second Real World Haskell and add: "Haskell: The Craft of Functional Programming".

unclerojelio
+1  A: 

I really found value in A taste of Haskell. It's a talk given by Simon Peyton Jones. It's a really nice overview and first look at the language, targeted at non-FP programmers.

Part 2 of the talk and a PDF of the slides. The camera never shows the slides, so the PDF really helps.

Chris Connett
A: 

Lisps are the only ones with a regular syntax at the core and well-defined standards (in the case of CL and Scheme). They make up for an enlightening ride.

I recommend Common Lisp.

There are good and free beginner's books on it, check out Lamkins' "Successful Lisp" and Seibel's "Practical Common Lisp":

skypher
IIRC, Standard ML has a formally-specified standard whereas Common Lisp and Scheme do not (they are only informally specified).
Jon Harrop
+6  A: 

One of the best tutorials for functional programming (a friend gave me) is Learn You a Haskell for Great Good!. This tutorial is about Haskell, but the basics there are very good presented in the right order. I found it very clear.

The_Ghost