
Ask HN: which functional language to learn? - vijayr
I'm looking at learning a functional programming language, but not able to decide which one.  The language should be fun to learn and also have decent job opportunities.<p>Based on some initial reading, Haskell and Erlang seem to be good choices.  Can anyone suggest a language?<p>My background (not sure if it matters) I've worked with Java/PHP/Ruby, developing desktop and web applications.
======
rosejn
Clojure. Without a doubt. It's by far the easiest and most productive Lisp
around right now. You get a modern core library with great support for
concurrency, and you can use Java libraries with ease. The new Clojure book
published by the Pragmatic Programmer guys a pretty good read, and it gets
into the important aspects of functional and concurrent programming. I've been
having a blast so far.

~~~
c00p3r
How big should be the server to run this site (with all its traffic), if it
could be ported from ark to Clojure? =)

------
babo
What about clojure? With a Java background it's easier to grasp, has all the
modern features and a friendly, supportive community. It's load of fun, you
could even use SICP with it. For job opportunities you need a good load of
luck with any functional language. With such a close integration with Java you
have a high chance for a stealth clojure project. :-)

------
michael_dorfman
I'd suggest Scheme, just because the SICP videos make learning it easy and fun
([http://groups.csail.mit.edu/mac/classes/6.001/abelson-
sussma...](http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-
lectures/)). And, once you get the functional concepts, Haskell and/or Erlang
should be relatively easy.

~~~
_giu
I think this is a good idea to first learn the basic functional concepts using
Scheme and the SICP videos (heard a lot of good things about the videos and
the book). I'm learning Haskell (I'm a C# guy) and some things are a _bit
difficult_ to understand if you have an _object oriented_ background. I think
I'll have a look at the SICP videos, too

~~~
vijayr
Did you learn Scheme and then moved to Haskell, or directly started with
Haskell?

~~~
_giu
I directly started with Haskell, but had some difficulties with the functional
concepts! this is why I second the idea of michael_dorfman. I think it will
help you a lot to understand everything _better_. and I personally like video
lectures a lot. not that I'm lazy and don't want to read, but sometimes, when
something is explained visually or by a specialist in the specific field, you
just _get it better_ in your head :)

------
apgwoz
I think this comes up enough that we should have some sort of FAHN: Frequently
Ask(ed) Hacker News.

That said. Scheme with SICP, or The Little Schemer and then SICP

~~~
sdevlin
I've got to second The Little Schemer. I ran through it earlier this year, and
it was the most fun I've had programming in a long time.

------
wilkes
Haskell:

<http://learnyouahaskell.com/>

<http://book.realworldhaskell.org/read/>

~~~
caffeine
Notes about Haskell:

It's strange, but Haskell is more difficult to read than write. This is
because most code on e.g. Hackage uses some very complicated gymnastics
involving Applicative, Arrows, or whatever. So it's hard to learn from other
people's programs.

Also, a warning: learning Haskell might screw with your ability to write code
in other languages! It took me two weeks before I stopped making every line of
Python a lambda.

~~~
baguasquirrel
I'm really curious to see how other people are progressing through the
learning process for Haskell (and other HM-based functional languages). I
rarely use lambdas, and I feel that Haskell is much easier to read than to
write. Clearly there's something different about our approaches. I learned SML
back in school, picked up OCaml about 3 years ago, and picking up Haskell was
_still_ a bit of a trip.

~~~
samstokes
I also find I use lambdas less in Haskell than in other languages. I think
it's because in Haskell, constructs like partial application, function
composition or lifting are concise and natural to express, and those
constructs cover most common use cases for an anonymous function. I think

map (find needle) haystacks

is clearer (as well as shorter!) than

map (\haystack -> find needle haystack) haystacks

In most other languages things like partial application are a pain to express,
so a lambda is an easier way out.

(Now I'm imagining the six lines of Java I'd have to write to achieve the same
effect as those four words of Haskell, and trying not to giggle. Functional
style is addictive.)

------
marcocampos
In my opinion don't learn any LISP, Common LISP or Scheme, it doesn't matter.
Why? Fragmentation. It's very hard to write something a bit complex that can
run on the various LISP compilers/interpreters without heavy changes. Also,
there is a lack of good and up-to-date 3rd party libraries/frameworks which
leads to having to write things that most languages already provide by default
or than can be easily obtained.

Go with Scala, Clojure or Haskell. The first two run over the JVM and seem to
have a very nice community behind them. Haskell is very cool and it will
definitely change the way you look at programming.

There is also F# which is very cool and runs over the .NET framework. If
you're into Microsoft stuff then it might be worth it.

~~~
cema
Well, technically Clojure is a lisp, but it does indeed depart from the
heavyweight lisp legacy as represented by Common Lisp. And portability is much
easier when all your libraries are in JVM. :-)

Scala started earlier than Clojure and has a bigger community around it.
Clojure is clean and grows quickly, it has a very good potential. Besides, it
has a strong and multifaceted support for parallel (multicore) programming.
Both Scala and Clojure run on top of JVM and interop with it.

Haskell has had a strong following in academia for quite a while now. Newer
languages borrow from it.

I have not tried F# which, as far as I understand, is a kind of ML on .NET.
Its community seems to be smaller, but it may be due to the usual animosity
some people feel regarding anything that comes out of Microsoft. Reportedly
the language is well designed.

~~~
marcocampos
Maybe F# acceptance will grow when Visual Studio 2010 comes out, since it will
be one of three new native languages: IronPython, IronRuby and F#.

~~~
cema
It may happen, but it would compete with the well established Ruby and Python
(in addition to C# and VB). Anyway, I am glad that they will be added to the
bunch.

------
troels
Ruby, used that way, is quite a functional language. I think you might find a
lot of similarities to Scheme, which might make it easier to get in to. I know
I did (although reversed .. I learned Scheme first).

------
johnbender
Haskell is a bit into the weeds if you're just starting out. I jumped in with
Erlang, as its pretty pragmatic so the tutorials out there tend to focus on
getting crap done and not so much theory.

Once you've written some code and feel comfortable with FP, then drink the
Haskell-aid.

------
Stasyan
I learned OCaml first, and then switched to F#. Out of all languages I know
(OCaml, Java, C#, C++, Python, VB, Lisp) - IMHO F# is the best one. Learning
curve is pretty steep though, once you move past the basics.

~~~
zikzikzik
> Learning curve is pretty steep though

Do you mean it gets difficult, or that progress gets fast?

~~~
Stasyan
It gets difficult. F# has pretty much everything from every other functional
language. Even though F# is very consistent language. There are a lots of
concepts to understand.

~~~
noblethrasher
No, it has just a few concepts that if taken _seriously_ (i.e. don't try to
write imperative/prescriptive code) will lead to the natural discovery of many
of its other features (or you'll end up inventing them yourself).

~~~
Stasyan
I am talking about continuations and workflows -> these concepts are not that
straight forward, especially if you are coming in from imperative programming
background.

~~~
noblethrasher
Fair enough. What I mean is that F# (and Haskell) can be useful without
knowing about Workflows (and Monads). By the time you find yourself needing
them you'd either invent them (fairly easily) or find them... It's not much
harder than INNER JOIN in SQL which I also think most people would eventually
invent if the language didn't have it.

------
cema
Clojure. It's a lisp on JVM.

------
troels
One more thing that you may or may not know is that functional programming
languages are a kind of fuzzy concept. There are at least two different
categories (well, probably it's more a continuum, but ..), being functional
programming languages vs. function-level programming languages. (Note: Someone
please correct me, if I'm confusing the terms here). Lisp's belongs in the
first category, where Haskell probably belongs in the latter. The first
category is more similar to main stream, procedural languages, where the
latter is more abstract. Which is a better choice is open for debate; On the
one hand, you'll probably grasp Lisp faster than Haskell, on the other hand
you might end up writing procedural code in it, instead of function oriented
code.

See: [http://en.wikipedia.org/wiki/Function-
level_programming#Cont...](http://en.wikipedia.org/wiki/Function-
level_programming#Contrast_to_functional_programming)

------
unignorant
I recently asked myself the same question, and I ended up settling on SBCL
(Common Lisp).

Emacs coupled with SLIME provides the best development environment I have yet
experienced. For me, the greatest downside is that the code I end up with is
often quite system-specific.

~~~
cema
I too settled on SBCL for a while, but then looked around a bit wider. Clojure
is an intriguing development. I recommend that you look at it, both the
language and the community. It has a good promise, borrowing the best from the
older lisps and leaving behind the unnecessary legacy.

So, unless you need to support or interact with past Lisp code, I think
Clojure may be a better tool for most of us. YMMV, as usual.

------
noblethrasher
As I'm sure you know, functional programming is a style and you can use it for
any of the languages you mentioned (yes, including Java - objects are a poor
man's closure but closure's are a poor man's object) [1]. One thing that
_might_ help is to try using functional idioms in the languages you know. Then
you'll appreciate the syntatic help that "real" functional provide for that
style.

[1][http://people.csail.mit.edu/gregs/ll1-discuss-archive-
html/m...](http://people.csail.mit.edu/gregs/ll1-discuss-archive-
html/msg03277.html)

------
mvalente
Javascript

~~~
cema
Javascript is a great language (and widely misused, alas). However, calling it
a functional language is a very big stretch (unlike lisp).

~~~
troels
Javascript has a lot of Scheme legacy. I'd definitely call it a functional
language.

~~~
cema
Javascript can be used that way, and some of Javascript technologies suggest
that, but it can and usually is used in the mainstream imperative way. People
who have not been exposed to functional programming before touching Javascript
(which is an overwhelming majority) may not even know about its functional
capabilities.

------
xtho
In consideration of your background, scala would come to mind. There is some
dispute about whether it's a functional language, though.

------
Tangurena
I work for a "microsoft shop." This means that if there is an MS and a non-MS
choice of technology, we'll always take the MS one. Consequently, F# is the
only possible choice for a functional language at work.

~~~
cema
I too work for a Microsoft shop. Installed Emacs, perl, MinGW/MSys with bash,
cygwin (do not use it, though), python (do not use it), etc. JVM is already
installed on all computers except the production servers. So the work that is
of a "personal" scope (editing a file, analyzing a log, etc) I can use any
technology which is available to me.

Of course, when we are talking about a group effort, we need a technology that
everyone in the group is understanding. It is more difficult to convince
others (including management) in a Microsoft shop to use non-Microsoft
technologies. But it is possible.

