Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask: Functional Programming: Where to Start?
7 points by euroclydon on March 4, 2009 | hide | past | favorite | 9 comments
The, "Why I Hate Lisp" post that's been on the top of the page all day finally prodded me to start reading PG's writings on Lisp. I have a BS in Math, so my curiosity is piqued and I want to start learning functional programming.

Currently I develop in C#, Javascript, Python, PHP, and Java (ordered by proficiency).

I want to get suggestions from the HN community on which functional language (or language that supports functional-esque programming) is the best place to start with the criteria for "best" being, you can also recommend a well written book to go along with the language and that the language might allow me to leverage my current experience (unless the pure kick-ass-ness of the language outweighs any benefit I might gain by leveraging my experience. i.e. Scheme > F#).

Thanks!



Most people would say start with SICP (http://mitpress.mit.edu/sicp/), and I think I would agree. It really stresses higher order programming.

OCaml would be nice too, for you, since F# is at least as powerful as it, and you could start using that in your C# environment.


Another good place to start would be Haskell. Real World Haskell is a good book, and there are several resources to get you started on the web (http://learnyouahaskell.com/ , http://en.wikibooks.org/wiki/Haskell/YAHT ).

I just started immersing myself in RWH (had to take a brief break from it because I switched clients) but I really liked the book.

Naturally I agree with apgwoz that SICP is another good place to start if you decide to go with Scheme. It is definitely a book every programmer should read, so you do get two for the price of one ;-)

Good luck.


Since you explicitly mentioned C# and F#, I'd suggest OCaml. There's a free translation of a French O'Reilly book, _Developing applications with Objective Caml_, at http://caml.inria.fr/pub/docs/oreilly-book/ (the site seems to be down for me at the moment). The first few chapters focus on functional programming, then imperative programming, then compare their strengths, weaknesses, and when using each is most appropriate. (OOP and others are covered later in the book.) It's a pretty good intro to FP, imho.

Once you know FP techniques, you can apply them in many languages people don't tend to think of as functional (though tail-call optimization helps, and support for higher-order functions is all but necessary); I write strongly FP-influenced code in Lua, for example.

Scheme is also an utterly fantastic language, but I'm going to defer recommendations there to others. (Except: I really like Chicken - http://www.call-with-current-continuation.org/)


Erlang is a nice, practical one that has some very evident sweet spots and is good in the real world. Haskell seems to be where a lot of the academic world is at, if you're going for something that's more a learning experience rather than something strictly practical (not to say you can't do real world stuff with Haskell, but historically, that hasn't been its emphasis).


No matter which language you choose for productivity, I would start with the exercises in the Little Schemer or Little MLer. They're disarmingly simple while still challenging your brain to shift into a recursive/applicative mindset.

As for what functional language you want to end up using...well, it depends on your goals.

I'm personally partial to the family of languages which use ML-style type systems, which include OCaml, F#, and Haskell.

The core of F# and OCaml are very similar. F# has better libraries whereas OCaml has both a more powerful type system and more powerful module system.

Haskell is less straight forward than OCaml and F# and has many more esoteric features you need to learn before being considered an expert. Nonetheless, many have found the process of learning to be a mind-expanding process. Also, the Haskell community is much larger and more vibrant than what you'll find with any other statically typed functional language.


Thanks. Besides being great for my mind, can I compile an assembly in F# and include it in my .NET application? And if so, do you have any real world examples of this being useful?


Get the little schemer. It shows basics of functional programming. Download PLTScheme it's easily the best environment for scheme. Try the examples to get a hang of it.


SICP, hands down. If you have some extra time you can watch the lectures on google video.

Paul Graham's ANSI Common Lisp is a useful supplement but it's not as entertaining as his essays.

If you're learning FP, you're learning AI. Peter Norvig's Paradigms of Artificial Intelligence Programming is the best book for applied FP.

Finally, the best way to learn Lisp is to write your own. It's the easiest language to write and in my opinion the only way to appreciate it.


I second the other suggestions. However since you already know Python, for a smooth start you can explore its FP capabilities: There's map, filter and reduce built-in.

I found SICP nice. You can try to do the exercises in Haskell, too.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: