Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Learning functional programming

31 views
Skip to first unread message

Michael Thaler

unread,
Oct 29, 2007, 3:55:18 PM10/29/07
to
Hello,

I would like to learn functional programming and I want to know the best
language for it. I know C, C++, Java, C# and Visual Basic and I tried to
learn some Haskell, but I have to admit I never really liked Haskell (I am
not really sure about the reason, maybe because it is a bit too academic).

I am thinking about Lisp, because there seem to be a lot of excellent Lisp
books. But I am not really sure if Lisp is a good way to learn functional
programming.

What language would you recommend for someone who knows object-oriented
programming and wants to learn functional programming? Why would you
recommend that language? What books can you recommend?

Thanks a lot in advance,
Michael

namekuseijin

unread,
Oct 29, 2007, 8:29:06 PM10/29/07
to
On 29 out, 17:55, Michael Thaler <michael.tha...@physik.tu-

muenchen.de> wrote:
> I would like to learn functional programming and I want to know the best
> language for it. I know C, C++, Java, C# and Visual Basic and I tried to
> learn some Haskell, but I have to admit I never really liked Haskell (I am
> not really sure about the reason, maybe because it is a bit too academic).

You could try OCaml, from the ML family. It's generally regarded the C
++ of the functional world: fast, practical, somewhat ugly. A lot
less bloated, of course.

It also boasts the OO paradigm (hence, the name) and direct imperative
constructs where you see fit (rather than Haskell's insistence on
purity via monads)...

> I am thinking about Lisp, because there seem to be a lot of excellent Lisp
> books.

if by Lisp you mean Common Lisp, forget it: it's just about as much
about imperative programming as C++, specially as much of its users
nowadays hail compilation and optimization above all.

You could try Scheme, which is a far more applicative and functional
Lisp. But if you've hated Haskell because it's "academic"...


rubymaverick

unread,
Oct 29, 2007, 10:28:42 PM10/29/07
to
On Oct 29, 3:55 pm, Michael Thaler <michael.tha...@physik.tu-

Michael, I too am just starting to learn functional languages, so I
might be able to point you in a couple of directions and give you some
resources to hit the ground running.

I have started by taking the OpenCourseWare course Structure and
Interpretation of Computer Programs at MIT:

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

It's basically the first comp sci class students take at MIT, online,
for anyone to 'take'. The book the class uses is under the same name,
Structure and Interpretation of Computer Programs (or SICP for short)
which is free online. The class focuses on functional languages in
general using Scheme as a point of reference, which is a simplified
LISP language. I decided to learn scheme first because I wanted to
grep the ideas of functional programming before really having to learn
a language because its such a fundamental shift from how things are
done in imperative languages.

After completing the course I think I may read The little schemer:
http://www.ccs.neu.edu/home/matthias/BTLS/

Also check out a post i just wrote about starting to learn functional
languages:

http://www.last100meters.com/2007/10/26/functional-programmers-are-the-long-tail

Again, im a functional noob so you may want to wait for some more
seasoned advice before jumping into my suggestions, but so far I think
I chose the right path.

Erik de Castro Lopo

unread,
Oct 30, 2007, 12:29:19 AM10/30/07
to
namekuseijin wrote:

> On 29 out, 17:55, Michael Thaler <michael.tha...@physik.tu-
> muenchen.de> wrote:
>> I would like to learn functional programming and I want to know the best
>> language for it. I know C, C++, Java, C# and Visual Basic and I tried to
>> learn some Haskell, but I have to admit I never really liked Haskell (I
>> am not really sure about the reason, maybe because it is a bit too
>> academic).
>
> You could try OCaml, from the ML family. It's generally regarded the C
> ++ of the functional world: fast, practical, somewhat ugly. A lot
> less bloated, of course.

I would second the recommendation for trying Ocaml, especially
if you found haskell too academic.

Ocaml is, above all a practical and pragmatic language. Companies
like Jane St Capital (see the article in issue 7 of "The Monad
Reader") and XenSource among others are using Ocaml for real
world problems.

Ocaml encourages you to write pure static single assignment functional
code. However, when that is not enough, you can drop back to imperative
coding and uses references (ie mutable variables). It even offers OO
for situation when OO is needed (apart from using the Ocaml GTK
bindings I personally have never seen the need).

One final piece of advice; if you do start learning Ocaml, try to
avoid the OO stuff as long as possible, and also avoid for/while
loops and references for a month or two. This will force you to
learn and use functional programming idioms instead of the imperative
ones you are probably used to.

Erik
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
From Time magazine, "Numbers" section:
$5 million: Estimated annual cost for a 10-year program that
would identify large asteroids most threatening
to earth.
$75 million: Budget for "Deep Impact", a film about the
devastation caused when a comet hits earth.


Torben Ægidius Mogensen

unread,
Oct 30, 2007, 4:35:06 AM10/30/07
to
Michael Thaler <michael...@physik.tu-muenchen.de> writes:


> What language would you recommend for someone who knows object-oriented
> programming and wants to learn functional programming? Why would you
> recommend that language? What books can you recommend?

Since you didn't like Haskell, I second the suggestions for a language
in the ML family. Since you mentioned using C#, F# (a variant of
OCaml for .NET) might be a good choice. There are to my knowledge no
books dedicated to F# (though John Harrop is working on "porting" his
OCaml book to F#), but you should be able to learn F# using OCaml
books, since the differences are minor.

Standard ML might be another choice. There are many different
implementations around, allowing you to choose between fast
compilation, fast code or a balance in-between. And there are a lot
more books teaching Standard ML than OCaml.

Or you could try Erlang. This functional language has become
increasingly popular for concurrent applications. Unlike the ML
languages above, it is dynamically typed (like Python etc.), and some
people find the syntax more arcane.

Torben

Paul Rubin

unread,
Oct 30, 2007, 1:20:23 PM10/30/07
to
Michael Thaler <michael...@physik.tu-muenchen.de> writes:
> I am thinking about Lisp, because there seem to be a lot of excellent Lisp
> books. But I am not really sure if Lisp is a good way to learn functional
> programming.

As others have said, certainly not Common Lisp. You might try Scheme.
You might also try Hedgehog Lisp (google for it), a tiny functional
Lisp dialect intended for small embedded systems.

> What language would you recommend for someone who knows object-oriented
> programming and wants to learn functional programming? Why would you
> recommend that language? What books can you recommend?

First of all, Hughes's famous paper "Why Functional Programming
Matters". Second, maybe SICP: http://mitpress.mit.edu/sicp if you're
interested in Scheme.

Pascal Costanza

unread,
Oct 30, 2007, 2:57:22 PM10/30/07
to
namekuseijin wrote:
> On 29 out, 17:55, Michael Thaler <michael.tha...@physik.tu-
> muenchen.de> wrote:
>> I would like to learn functional programming and I want to know the best
>> language for it. I know C, C++, Java, C# and Visual Basic and I tried to
>> learn some Haskell, but I have to admit I never really liked Haskell (I am
>> not really sure about the reason, maybe because it is a bit too academic).
>
> You could try OCaml, from the ML family. It's generally regarded the C
> ++ of the functional world: fast, practical, somewhat ugly. A lot
> less bloated, of course.
>
> It also boasts the OO paradigm (hence, the name) and direct imperative
> constructs where you see fit (rather than Haskell's insistence on
> purity via monads)...
>
>> I am thinking about Lisp, because there seem to be a lot of excellent Lisp
>> books.
>
> if by Lisp you mean Common Lisp, forget it: it's just about as much
> about imperative programming as C++, specially as much of its users
> nowadays hail compilation and optimization above all.

That's nonsense. You can do functional programming in Common Lisp as
well as in Scheme. There is no preference in Common Lisp for imperative
programming (but it's also not discouraged), and there is no fixation on
compilation and optimization in the Common Lisp community.

Scheme is somewhat neater if you need/have a lot of higher-order
functions, though.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/

Donn Cave

unread,
Oct 30, 2007, 3:00:12 PM10/30/07
to
In article <4726b...@news.peopletelecom.com.au>,

I agree that ocaml is a very practical language, but then this
last paragraph brings up a sort of a conundrum here, for me anyway.

If I want to learn functional programming per se, that objective
itself is in some sense academic. Your advice, to stay away from
a handful of "practical" elements of the language, is very well
taken -- and utterly academic.

Whether Haskell is practical or not, I wouldn't want to take a
position on that. If commercial use here and there is proof, then
I think Haskell has proof, but I think its practicality remains
a very interesting issue. I'm just saying that "academic" is in
our heads, not in the language, and if the original poster has
a problem there, it might make sense to refine that point a little.

Donn Cave, do...@u.washington.edu

Greg Buchholz

unread,
Oct 30, 2007, 8:29:58 PM10/30/07
to

Michael Thaler wrote:

> What language would you recommend for someone who knows object-oriented
> programming and wants to learn functional programming? Why would you
> recommend that language? What books can you recommend?

Besides the other recommendations, you might also want take a look
at the Q language [1]. The syntax is similar to Haskell, but it is
eagerly evaluated and dynamically typed. As for books, I liked "The
Haskell School of Expression" [2], and "ML for the Working
Programmer" [3] but then I also like Haskell.

1. http://q-lang.sourceforge.net/about.html
2. http://haskell.org/soe/
3. http://www.cl.cam.ac.uk/~lp15/MLbook/

Jon Harrop

unread,
Oct 30, 2007, 8:27:31 PM10/30/07
to
Pascal Costanza wrote:

> namekuseijin wrote:
>> if by Lisp you mean Common Lisp, forget it: it's just about as much
>> about imperative programming as C++, specially as much of its users
>> nowadays hail compilation and optimization above all.
>
> That's nonsense. You can do functional programming in Common Lisp as
> well as in Scheme. There is no preference in Common Lisp for imperative
> programming (but it's also not discouraged),

There is little to no support for functional programming. Even function
application is absurdly tedious in Lisp.

> and there is no fixation on compilation and optimization in the Common
> Lisp community.

Lisp being very slow is hardly an advantage.

Lisp is an antique that you might enjoy tinkering with but all modern
functional programming languages employ a variety of constructs far beyond
the capabilities of Common Lisp. Don't bother with Lisp or any of its
dialects. Learn a modern language that gets functional programming right
first.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u

Jon Harrop

unread,
Oct 30, 2007, 8:38:08 PM10/30/07
to
Michael Thaler wrote:
> Hello,
>
> I would like to learn functional programming and I want to know the best
> language for it. I know C, C++, Java, C# and Visual Basic and I tried to
> learn some Haskell, but I have to admit I never really liked Haskell (I am
> not really sure about the reason, maybe because it is a bit too academic).
>
> I am thinking about Lisp, because there seem to be a lot of excellent Lisp
> books. But I am not really sure if Lisp is a good way to learn functional
> programming.
>
> What language would you recommend for someone who knows object-oriented
> programming and wants to learn functional programming?

OCaml under Linux or Mac OS X and F# under Windows. If you are using C# and
VB then I assume you're working under Windows in which case you can benefit
from F#'s integrated development support provided by its Visual Studio plug
in.

> Why would you recommend that language?

As a functional programming language, F# is among the best. It provides
modern features like an expressive static type system, pattern matching and
OOP as well as being practical. The F# language is also being pushing into
the mainstream by Microsoft, who recently announced its productization.

Both OCaml and F# make it easy to transition from a heavily mutating
programming style because they combine familiar imperative features with
high-performance functional programming constructs.

> What books can you recommend?

"Foundations of F#" by Robert Pickering is specifically targetted at OO
programmers. Don Syme et al's forthcoming book "Expert F#" is superb and
has just gone to the publishers.

I recommend modern books that cover statically typed FPLs over out of date
books like Structure and Interpretation of Computer Programs. I would also
strongly advise against learning a dynamically typed FPL like Lisp or
Scheme first because it leaves you wrong-footed for learning the more
popular modern functional programming languages. If you would like to try a
dynamically typed FPL then have a play with JavaScript.

sbake...@aol.com

unread,
Oct 31, 2007, 2:28:07 AM10/31/07
to
> Besides the other recommendations, you might also want take a look
> at the Q language [1]. The syntax is similar to Haskell, but it is
> eagerly evaluated and dynamically typed.

I second the recommendation for Q, except that I disagree that it has
a syntax similar to Haskell.

Q is interesting in that it is based on term-rewriting. Also, dynamic
typing, and in most cases, no need to declare the type of a variable.

Rainer Joswig

unread,
Oct 31, 2007, 7:26:38 AM10/31/07
to
In article <fg5dr9$v7b$1...@news.lrz-muenchen.de>,
Michael Thaler <michael...@physik.tu-muenchen.de> wrote:

Scheme, a Lisp dialect, is fine for learning Functional Programming.
There are a lot of good books and implementations.

This gives a list of the introductory texts.
http://www.schemers.org/Documents/#intro-texts

Check out http://www.htdp.org/ .
The older SICP is still useful to read (or view, if
you see some of the video lectures online) - some newer
texts have expanded on SICP. HTDP or 'Schematics of Computation'
are examples for that.

Later, you can learn for writing more ambitious software with little
difficulty Common Lisp. Scheme already covers a lot of
the basics...

Chris Rathman

unread,
Oct 31, 2007, 10:39:41 AM10/31/07
to
On Oct 30, 3:35 am, torb...@app-3.diku.dk (Torben Ægidius Mogensen)
wrote:

> Since you mentioned using C#, F# (a variant of
> OCaml for .NET) might be a good choice. There are to my knowledge no
> books dedicated to F# (though John Harrop is working on "porting" his
> OCaml book to F#), but you should be able to learn F# using OCaml
> books, since the differences are minor.

"Foundations of F#" from Robert Pickering is an introductory text for
F#. I'd recommend it for anyone wanting to learn F#, especially those
that are already familiar with C#.

Alexey Romanov

unread,
Oct 31, 2007, 4:44:12 PM10/31/07
to

And "Expert F#" by Don Syme (the main developer of F#) should be available
on November 30.
--
Alexey Romanov

"This is a crime so sneaky and so subtle, even I don't know if I
am actually committing it!"

Freefall <http://freefall.purrsia.com/ff800/fv00739.htm>

Michael Thaler

unread,
Nov 1, 2007, 8:51:22 AM11/1/07
to
Hi,

> I have started by taking the OpenCourseWare course Structure and
> Interpretation of Computer Programs at MIT:
>
>
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/CourseHome/index.htm
>
> It's basically the first comp sci class students take at MIT, online,
> for anyone to 'take'. The book the class uses is under the same name,

That sounds like a good idea to me. Which scheme compiler / interpreter are
you using? Is there a good scheme compiler / interpreter for Linux?

> LISP language. I decided to learn scheme first because I wanted to
> grep the ideas of functional programming before really having to learn
> a language because its such a fundamental shift from how things are
> done in imperative languages.

I think that's indeed a good idea.


> After completing the course I think I may read The little schemer:
> http://www.ccs.neu.edu/home/matthias/BTLS/

This seems to be a good book. It got lots of recommendations at Amazon.
Thanks for the tip.

> Again, im a functional noob so you may want to wait for some more
> seasoned advice before jumping into my suggestions, but so far I think
> I chose the right path.

I think your recommendations are pretty good. I am still not sure which
functional language I want to learn, but I will definitively have a look at
scheme.

Greetings,
Michael

Michael Thaler

unread,
Nov 1, 2007, 8:56:52 AM11/1/07
to
Hi,

> OCaml under Linux or Mac OS X and F# under Windows. If you are using C#
> and VB then I assume you're working under Windows in which case you can
> benefit from F#'s integrated development support provided by its Visual
> Studio plug in.

We are using .Net at work, but at home I am mostly using Linux. I might give
F# a try because we could even use it at work, especially if it becomes
officially supported by Microsoft.

Are there any good OCaml books that you can recommend?

> I recommend modern books that cover statically typed FPLs over out of date
> books like Structure and Interpretation of Computer Programs. I would also
> strongly advise against learning a dynamically typed FPL like Lisp or
> Scheme first because it leaves you wrong-footed for learning the more
> popular modern functional programming languages. If you would like to try
> a dynamically typed FPL then have a play with JavaScript.

Which books can you recommend here?

Greetings,
Michael

Michael Thaler

unread,
Nov 1, 2007, 9:05:37 AM11/1/07
to
Hi,

> eagerly evaluated and dynamically typed. As for books, I liked "The
> Haskell School of Expression" [2], and "ML for the Working
> Programmer" [3] but then I also like Haskell.

I don't really dislike Haskell. I've worked through most of the
book "Haskell, The Craft of Functional Programming" and I actually think
Haskell is a quite elegant and powerful language. I also think Hugs is a
quite nice environment to learn a language.

On the other hand, what I miss from Haskell is a standard GUI library. I
know Qt and from this point of view, Qt bindings would be excellent. Maybe
I should have a look at Scala, which can even be used with Qt (with Qt
Jambi).

I will definitively buy The Haskell School of Expression. I have this book
on my Amazon wishlist for a long time.

Greetings,
Michael

Torben Ægidius Mogensen

unread,
Nov 1, 2007, 9:47:24 AM11/1/07
to
Michael Thaler <michael...@physik.tu-muenchen.de> writes:


> On the other hand, what I miss from Haskell is a standard GUI library.

There are several GUI libraries, e.g., Gtk2Hs
(http://haskell.org/gtk2hs/overview/), but perhaps what you mean by
"standard" is that there should be only one?

Torben

Jon Harrop

unread,
Nov 1, 2007, 12:39:25 PM11/1/07
to
Michael Thaler wrote:
> We are using .Net at work, but at home I am mostly using Linux. I might
> give F# a try because we could even use it at work, especially if it
> becomes officially supported by Microsoft.

In theory you can also get F# running under Linux to some extent using Mono.
That would help you to learn the language. There is also a lot of overlap
between OCaml and F# so you could just work through some of the OCaml
tutorials under Linux and apply your knowledge directly to F# programming
at work.

> Are there any good OCaml books that you can recommend?

My own "OCaml for Scientists", the first chapter of which is freely
available:

http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html

There is also "Practical OCaml" from APress but my book was much better
received.

>> I recommend modern books that cover statically typed FPLs over out of
>> date books like Structure and Interpretation of Computer Programs. I
>> would also strongly advise against learning a dynamically typed FPL like
>> Lisp or Scheme first because it leaves you wrong-footed for learning the
>> more popular modern functional programming languages. If you would like
>> to try a dynamically typed FPL then have a play with JavaScript.
>
> Which books can you recommend here?

Our OCaml and F#.NET Journals go into great detail in the use of static
typing to improve program performance and reliability with many examples of
practical interest:

http://www.ffconsultancy.com/products/ocaml_journal
http://www.ffconsultancy.com/products/fsharp_journal

Look at the free first articles, in particular.

I am also currently enjoying Paul Hudak's excellent "The Haskell School of
Expression". From Standard ML, there is "ML for the Working Programmer" by
Larry Paulson. Haskell and SML are both interesting related languages but I
do not value much from the Lisp world.

Jon Harrop

unread,
Nov 1, 2007, 12:55:05 PM11/1/07
to
Michael Thaler wrote:
> I think your recommendations are pretty good. I am still not sure which
> functional language I want to learn, but I will definitively have a look
> at scheme.

If you haven't found them already, you may also like some of our tutorial
examples in OCaml and F#:

http://www.ffconsultancy.com/ocaml/index.html
http://www.ffconsultancy.com/dotnet/fsharp/index.html

We also have some free tutorial articles about the benefits of the OCaml
programming language:

http://www.ffconsultancy.com/ocaml/benefits/

Garry Hodgson

unread,
Nov 1, 2007, 2:07:57 PM11/1/07
to
Jon Harrop <use...@jdh30.plus.com> wrote:

> As a functional programming language, F# is among the best. It provides
> modern features like an expressive static type system, pattern matching and
> OOP as well as being practical. The F# language is also being pushing into
> the mainstream by Microsoft, who recently announced its productization.

to what degree is it useful on linux? i get the sense that there may be some
support via mono. does anyone actually use it that way? languages on
windows are of no real interest to me. but it sounds interesting enough that
i wouldn't mind checking it out if it's viable on linux.

----
Garry Hodgson, Senior Software Geek, AT&T CSO

nobody can do everything, but everybody can do something.
do something.

Jon Harrop

unread,
Nov 1, 2007, 9:13:50 PM11/1/07
to
Garry Hodgson wrote:
> Jon Harrop <use...@jdh30.plus.com> wrote:
>> As a functional programming language, F# is among the best. It provides
>> modern features like an expressive static type system, pattern matching
>> and OOP as well as being practical. The F# language is also being pushing
>> into the mainstream by Microsoft, who recently announced its
>> productization.
>
> to what degree is it useful on linux?

I believe it would be useful for learning a modern functional programming
language but I cannot think of any practical use that OCaml isn't already
better for.

> i get the sense that there may be some support via mono. does anyone
> actually use it that way?

I have heard of several Linux users of F#.

> languages on
> windows are of no real interest to me. but it sounds interesting enough
> that i wouldn't mind checking it out if it's viable on linux.

I think it is worth taking a look at. Operator overloading is a major point
of interest for me and I learned a lot by comparing and contrasting OCaml
and F# in this respect. Active patterns are very useful when your language
sits on a CLR because they allow you to provide friendly interfaces to
alien libraries, e.g. allowing pattern matching directly over .NET's OOP
representation of XML DOM trees.

Scala is also worth a look. I like some of its features but, overall, I do
not think it can compete with the likes of OCaml as a practical FPL.

According to the hype surrounding Scala and F#, there is great benefit in
building upon existing frameworks with many libraries. However, at least
for technical users, I believe that access to a wealth of existing
libraries in the form of .NET or the JVM is a red herring because the
libraries are largely irrelevant and you must still endure inexpressive
APIs. In contrast, OCaml has awesome libraries...

Marlene Miller

unread,
Nov 2, 2007, 12:16:19 AM11/2/07
to

"Michael Thaler" wrote

http://www.scheme.com/tspl3/
The Scheme Programming Language by Kent Dybvig

http://www.plt-scheme.org/software/drscheme/
an IDE

http://www.schemers.org/Documents/Standards/R5RS/

Scheme and the Art of Programming by George Springer and Daniel Friedman

http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/
a textbook on programming language theory that uses Scheme


0 new messages