Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
OCaml sync tool for Rex organizer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: Seeking pratical tutorial or examples.
> I have looked at the caml site, the hump and all I links I could
> find from the main site.

In my mind, it seems as if you have completely missed the FAQ of the
language ...

> Isn't there a code snippet/samples page?
> What I have tried so far are the intro on the Ocaml Manual,  the
> "Functional Programming using Caml light" and "One hundred lines
> of Caml".
> Comments on the 3 sources I mentioned above:
> ** Ocaml Manual: The intro is not bad, except that for those of
> us coming from languages without a built in interactive system
> we may not be as interested to start with that. Why? because
> although great for learning it is of not much use unless we just
> want to try simple things. [...]

Bizarre: you do not want to start by simple things ?

If you do want to start by material that are not ``simple things'',
you definitely have to read the pretty good bunch of examples that is
generally refered to as ``the Objective Caml compiler''. It is not
interactive, it is great for learning, and in some cases definitively
not simple (I would suggest the following road-map: start with the
Objective Caml libraries (directories stdlib and otherlibs), then
bravely start reading the compiler sources: first the Yacc parser and
its associated lexer (directory parsing), then take a breath and read
the type-checker (directory typing), breath again and continue with
the pattern matching compiler (directory bytecomp), then breath a lot
and end with the delicious native code compiler (directory asmcomp)).

> I think the following order may be more benefitial to someone
> coming from languages such as C/pascal.

Excellent: you are exactly describing the order of presentation of the
FAQ, that has been intended for just that kind of people. The first
page of the FAQ for beginners, has the following items entries, in
that order:

* What is the syntax of the language ? 
* What are the basic data structures ? 
  * Numbers: integers and floating point numbers. 
  * Characters 
  * Character strings 
  * Arrays 
  * Lists 
  * Booleans 
  * Nothing 
  * References 
  * Pairs 
  * Other data structures 
* What are the basic control structures ? 
  * How to perform a test ? 
  * How to perform a case analysis ? 
  * How to perform a test within a case analysis ? 
  * How to write a loop ? 
  * How to exit form a loop ? (break, exit, abort, return ...) 
  * How to catch errors ? 
  * How to signal errors (raise exceptions) ? 
  * What are the predefined exceptions (errors) ? 
* How to define a function ? 
* How to define a procedure ? 

> -Start by having something which shows a compiled program and a
> few basic statements (i.e. ask for name and then print hello
> <name>.

> -Cover data types and show the functions to read them and
> display them. No fancy explanation about "channels" just give
> examples using print functions and whatever is used to read info
> into a variable.

> -Loops and branching: "for" and "if"

While, match and exceptions are also covered.

> -Cover functions

> -Basic file I/O

Printing is also covered at:

> -String handling

> -More advanced data structures/types: arrays, user defined data
> types, lists.

> -The interactive system

> And of course on all those steps start showing the user the way
> things are written in Ocaml and how things are called in it.

The same references, plus the Quick Reference Guide for Caml that
gives you the syntactic constructs along with examples:

> ** Functional Programming using Caml Light
> I am up to chapter 5 and I am yet to dream of how to actually
> write a complete program. Even after I jumped chapters ahead to
> chapter 9, Basic I/O, there are one line descriptions or trivial
> use of the fucntions, but I didn't even see a simple brief
> program to show all elements together. The document almost seems
> like reference material, except that it is too
> descriptive/narrative to be that.

Right. It is not a reference manual, although it describes a
type-checker and a compiler for (a subset of) Caml.

> ** One Hundred lines of Ocaml: This is enough to give a "taste"
> of the language, but far from been enough to start hacking.

Right, it just appears in the FAQ under the title:
A taste of Caml

> Have a missed a kinder/gentler tutorial somewhere?

May be the FAQ ?

> Somewhere on the caml site I saw a mention about a series of
> examples that come with the compiler. The FreeBSD port I got
> didn't have them and I was unable to find them on the web site
> (

Those examples are written for Caml Light and burried from the book
``Le langage Caml''. I translated them into Objective Caml, but have
not linked them to the Caml web site, since there is no english
explanations on those examples (the book ``Le langage Caml'' has not
yet been translated into english).

> francisco
> Moderator of the Corporate BSD list

PS1: I hope you will find what you need in the FAQ. In any case,
please let me know if you have some addition to suggest to the FAQ's

PS2: Also, when you are writing your first big Caml programs, don't
miss the very relevant Caml Programming Guide Lines:

that also gives some useful hints on how to program in Caml.

Pierre Weis

Moderator of the Caml list