Jump to content
  • Advertisement
Sign in to follow this  
Gage64

Learning a functional language - which one?

This topic is 3775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've read many posts here saying that knowing a functional programming language will make you a better programmer, so I'm thinking about trying to learn one. The question is, which one? The ones that seem to be mentioned the most here are Haskell, Scheme, O'Caml and Lisp. Some other names I've heard are Clos, Ruby and F#. In terms of resources, it seems like Scheme would be the best choice. The book "Structure and Interpretation of Computer Programs" is freely available on the internet, and many people on Amazon seem to think it is absolutely revolutionary (though many people there also think it's a piece of junk). There's also a workshop here on GDNet that's based on that book, and there are even free video lectures from Berkley for a course based on that book. I've also read many posts that say that Haskell is very elegant compared to many other functional languages, but there might be less (free) resources for it? What would you recommend and why? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Speaking from experience, Lisp is a very nice language for learning functional programming. When I say "Lisp", I mean both Common Lisp and Scheme - they are both Lisp dialects and either choice will serve you well.

Haskell is also a nice choice, but it's a bit tougher to learn, mostly because it forces you to use functional programming whereas Lisp lets you get away with some shortcuts. The one thing I don't like about Haskell is that it forces you to structure your tabs in a certain way.

As far as resources go, Lisp is definitely the better documented language. There is also no shortage of Lisp compilers/interpreters and even libraries to use Lisp as a scripting language together with, for example, C++. Haskell is more limited in that regard.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
...and many people on Amazon seem to think it is absolutely revolutionary (though many people there also think it's a piece of junk).


I don't have much experience with functional languages but they do tend to be quite polarising. You either love it or you hate it!

Anyway I studied some Haskell at university and it was interesting - though I'm not sure it made me a better programmer. Otherwise I've heard good things about Scheme.

It's interesting that you mention F# - I don't know how much of a serious functional language this is but having the .NET libraries available means you can write more interesting programs (and therefore be more motivated) than with the other languages.

Share this post


Link to post
Share on other sites
Going with Haskell would be jumping off the deep end. It's a pure functional language, which means that simple things you're used to, like creating a storage for random read/write access (i.e. a simple variable in imperative languages), become complicated.

Haskell, and ML-variants (SML and O'Caml) are statically typed, Lisp and it's variants (Scheme) are dynamically typed. That is a very important distinction that significantly affects the overall programming style.

Lisp programs are actually lists that can be manipulated by Lisp programs themselves, allowing many very interesting and (excessively) clever techniques, at the expense of a somewhat cumbersome syntax.

I haven't tried all of the languages you listed but my suggestion is to start with O'Caml. Besides being a functional language, the static type system is just fascinatingly powerful. And the learning curve shouldn't be too high. You should have no particular difficulties in writing simple programs straight away, once you get the hang of the syntax.

Share this post


Link to post
Share on other sites
You might be interested in this:

http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/CourseHome/index.htm

Share this post


Link to post
Share on other sites
Quote:
Original post by Cromulent
You might be interested in this:

http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/CourseHome/index.htm


Thanks. If I go with Scheme, I will probably use the Berkley course because it has free video lectures, but the notes at that link might be a nice addition.

I probably should have mentioned that I am not new to programming in general and am fairly proficient with C++. Does that change anything regarding which language I should pick?

Thanks for your thoughts everyone, and keep 'em coming!

Share this post


Link to post
Share on other sites
I just discovered that the book "The Haskell Road To Logic, Maths And Programming" is also freely available online (though some sites only list sample chapters. I hope it is legally free?)

This book seems to teach Haskell in conjunction with various math topics. It seems to get good reviews on Amazon, but I have two things that potentially bother me with it.

First, because of the focus on math, the book probably doesn't go in-depth about the language and it's advanced features. It also means that the scope is very narrow (for example, there won't be code examples that show how to create a simple interpreter, which I've heard functional languages are very suited for).

Second, the topics seem to coincide with those covered in a Discrete Math course, which I already took (I'm a CS student, 1st year). I can't say that I have a good grasp of them though, and we didn't devote a lot of time to Logic (which was the subject that interested me the most), but this book also seems to cover it in just one chapter.

What are your thoughts on this book? Would it be better to use a book that is more "programming-oriented"? Can you recommend such a book? (It doesn't have to be about Haskell.)

Share this post


Link to post
Share on other sites
Well I just finished a C++ class and am also looking to learn a functional language and this free online book caught my eye since it builds a BASIC compiler in one of the chapters!
Computer Science Logo style
I skimmed through some of the chapters and I really liked what I read.
Plus I like the idea of learning Lisp without all the parentheses which really turned me off to learning it when I first heard about it!
"Logo is a computer programming language used for functional programming. It is an easier-to-read adaptation and dialect of the Lisp language; some have called it Lisp without the parentheses. Today, it is known mainly for its turtle graphics, but it also has significant facilities for handling lists, files, I/O, and recursion." -Wikipedia
Here's a sample program in Logo that should impress you
Here is a short but complete program in Berkeley Logo:

to choices :menu [:sofar []]
if emptyp :menu [print :sofar stop]
foreach first :menu [(choices butfirst :menu sentence :sofar ?)]
end

And here's how you use it. You type

choices [[small medium large]
[vanilla [ultra chocolate] lychee [rum raisin] ginger]
[cone cup]]

and Logo replies

small vanilla cone
small vanilla cup
small ultra chocolate cone
small ultra chocolate cup
small lychee cone
small lychee cup
small rum raisin cone
small rum raisin cup
small ginger cone
small ginger cup
medium vanilla cone
medium vanilla cup
medium ultra chocolate cone
medium ultra chocolate cup
medium lychee cone
medium lychee cup
medium rum raisin cone
medium rum raisin cup
medium ginger cone
medium ginger cup
large vanilla cone
large vanilla cup
large ultra chocolate cone
large ultra chocolate cup
large lychee cone
large lychee cup
large rum raisin cone
large rum raisin cup
large ginger cone
large ginger cup

The program doesn't have anything about the size of the menu built in. You can use any number of categories, and any number of possibilities in each category. Let's see you do that in four lines of Java!

p.s. I wouldn't consider Ruby a functional language as I wouldn't consider Python a functional language. It has some stuff for functional programming but that's it.

[Edited by - daviangel on May 25, 2008 5:09:13 PM]

Share this post


Link to post
Share on other sites
I've never understood why people complain about the abundance of parentheses in Lisp. Together with parenthesis highlighting, it makes the structure of your programs extremely clear. This is especially critical in Lisp, where everything (even programs themselves) are lists which consists of cons-cells; this allows some extremely powerful programming techniques but would not be possible without an unambiguous way to tell statements apart.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!