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
[Caml-list] baffled by semicolon
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <hars@b...>
Subject: Baffeld by manual (Was: [Caml-list] baffled by semicolon) wrote:
 > I went back through the manual and really couldn't find anything which
 > explained the difference between ; and ;;

Yeah, this is a bug in section 1.5 "Imperative Features" of the manual. (IMHO, 
the whole Part I is not what it claims to be and the Ocaml team should stop 
calling it an introduction into the language, but I've said that before

Now, if you want to be anal, you might say that all that needs to be said is 
indeed said in the manual, in section 6.7.2 "Control Structures"

| The expression expr1 ;  expr2 evaluates expr1 first, then expr2, and returns 
| the value of expr2.

together with section 6.11.2 "Structures":

| For compatibility with toplevel phrases (chapter 9) and with Caml Light, an
| optional ;; is allowed after each definition in a structure. The ;; has no
| semantic meaning. Also for compatibility, ;; expr is allowed as a component
| of a structure, meaning let _ = expr, i.e. evaluate expr for its
| side-effects.

But to find this section (and to see why it is indeed the answer to your 
question) requires some ingenuity, since you are not dealing with a structure 
proper, but with a compilation unit, and section 6.12 doesn't mention this 
peculiarity. You have to guess its relevance from the "behaves roughly as".

With this knoledge, you can see let your version with a single semicolon
 > let w = area#misc#realize ();
 >   area#misc#window;;

is equivalent to the definition:

let w = let _ = area#misc#realize () in area#misc#window

while the version with the double semicolon is

let w = area.misc.realize ()
let _ = area#misc#window

which binds w to unit and ignores the value of area#misc#window.

Yours, Florian

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: