Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] poll - need for a good introductory OCaml book (LONG)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sergey Goldgaber <sgoldgaber@y...>
Subject: Re: [Caml-list] poll - need for a good introductory OCaml book (LONG)
Disclaimer:  Sorry about the long-windedness of this, but I think
good, intuitive tutorials are some of the most important things a
language needs in order to be successful.  So I thought I'd share
my experiences with learning OCaml in some detail.


Graham Guttocks <graham_guttocks@yahoo.co.nz> wrote:
>
> There seems to me clearly, a lack of a good, tutorial style,
> introductory book about OCaml in English.  Something akin to
> ``Programming Perl'' (as someone mentioned).
> 
> I'm talking to a publisher at Manning (http://www.manning.com) about
> the possibility of such a book.  They are intrigued, but would like
to
> see some indication that people are interested.
> 
> Would you like to see such a book?

Oh, god YES!!  

I have been struggling to learn OCaml for over a month now.  It
is, without a doubt, the hardest language I have ever tried to
learn, and in some ways makes assembly language look simple and
intuitive by comparison.

Now, I am not a novice at programming.  I have used computers
since 1980, I know: C, Perl, Assembly, Pascal, Visual Basic, shell
scripting, Logo, REXX, SQL, HTML.  Picking up most any of those
(except for assembly) was a breeze.  But learning OCaml, as it is
my first functional language, is painful (until I have an "aha"
moment, when I glimpse its elegance and power, and all the pain
seems worth it).

I have gone through Bruce Hauman's "Intorduction to Ocaml"
tutorial, Scott Smith's lecture notes, and Jason Hickey's
"Intorduction to the Objective Caml Programming Language".

I have also read through parts of the O'Reilly book, but it really
wasn't doing all that much for me.  Also, I really like to have a
physical book in front of me (such a large online volume is
uwieldy, and it's too much to print out).

Fortunately, I managed to find Guy Cousineau's and Michel Mauny's
"The Functional Approach to Programming" used and got that.  I
have been slowly and steadily making my way through that, and it
covers the language in quite a bit of detail and in a good
tutorial matter, and I am generally very happy with it.  However,
I think the presentation of the material could be even better.
Also, it only covers Caml Light, so I think that might become an
issue at some point.

Coming from a purely imperative background I found the following
concepts the biggest stumbling blocks in my attempts at learning
OCaml: functional style, recursion, type inference

Of the three, I would say that in all of the material I have read
only type inference is covered in any serious detail.  And even
there the focus could be stronger and the explanations better.

Recursion is usually glossed over, and assumed to be just the
natural way to accomplish tasks.  When being taught most
imperative languages one is taught the very basics of recursion,
but actual use is comparatively rare.

As recursion is the mainstay of functional programming I think it
needs to be covered in a much, much more detailed, step-by-step
manner.  And many relatively basic exercises (with answers and
especially explanations of the answers) that should be done before
attempting any of the more advanced and complex OCaml idioms.

In your average Ocaml tutorial functional style is also not really
emphasized or explained well (if at all).  Sure, functional style
is used in the examples, but rarely is any attention given as to
why you would want to do things this way.

As OCaml offers one the choice of using an imperative style,
that's what I find myself naturally gravitating towards when I
start coding on my own (as opposed to solving toy problems for the
exercises).  I have to stop and force myself to think: "now how can
I do this in a more functional style, perhaps using recursion?"  

The tutorials show you how functions can be passed as arguments,
but for me it is so much more natural to just pass around normal
variables and values to distinct functions, rather than create a
series of functions each of which calls the next while passing
functions around.  This practical aspect of the functional style
is rarely explained.  You are shown that problems _can_ be solved
this way, but not really shown _why_ they should be solved this
way rather than in an imperative manner, or how you can think of
these complex constructions yourself.

Too much is ready-made in these tutorials.  "Here's a
Y-Combinator", "this is how it works".  But how would you ever
think of a solution like that yourself?  And why would you want to
rather than implementing an imperative solution?  That's what is
needed.

I think something like a "C Programmer's Introduction to OCaml" or
"From C to OCaml" book would be really great.  It should assume no
previous experience with functional languages, and perhaps could
start by showing the OCaml equivalents of C constructs like for
loops.  That will somewhat simplify learning OCaml's "strange"
syntax.  You could continue by focusing on OCaml's imperative
aspects, so that C programmers will quickly feel comfortable
because they are on home turf.  And only then, in the intermediate
and advanced sections of the book should you cover the functional
aspects of the language, again with plenty of juxtapositions
between the imperative and functional styles, and exercises,
exercises, exercises.

As for the object oriented aspects of OCaml, I have no comment
yet.  I'm saving trying to learn that until I feel very
comfortable with the functional aspects of the language.

But if you get the rest, and slap a "friendly" cover on (but not
too friendly, or it will seem like a "toy" language), I think
you'll have a hit.


  --Sergey


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners