From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA22440; Wed, 24 Dec 2003 10:49:57 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA22833 for ; Wed, 24 Dec 2003 10:49:56 +0100 (MET) Received: from mail2.tpgi.com.au (mail.tpgi.com.au [203.12.160.58]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBO9nrb14754 for ; Wed, 24 Dec 2003 10:49:54 +0100 (MET) Received: from 203-213-81-64-syd-ts13-2600.tpgi.com.au (203-213-81-64-syd-ts13-2600.tpgi.com.au [203.213.81.64]) by mail2.tpgi.com.au (8.12.10/8.12.10) with ESMTP id hBO9nmTl001710; Wed, 24 Dec 2003 20:49:49 +1100 Subject: Re: [Caml-list] Frustrated Beginner From: skaller Reply-To: skaller@ozemail.com.au To: Tyler Eaves Cc: caml-list In-Reply-To: <1072152186.59938.30.camel@tylere> References: <1072152186.59938.30.camel@tylere> Content-Type: text/plain Message-Id: <1072259385.2702.43.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 24 Dec 2003 20:49:47 +1100 Content-Transfer-Encoding: 7bit X-TPG-Antivirus: Passed X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ozemail:01 level':01 semantically:01 sequencing:01 endline:01 endline:01 'ocaml':01 compiler:01 ocaml:01 checking:01 syntax:02 syntax:02 parser:02 parser:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 2003-12-23 at 15:03, Tyler Eaves wrote: > So why is O'Caml giving me so much trouble? Because the syntax is foreign. > My biggest source of problems seems to be the syntax. I'm totally > confused as far as ; vs ;; vs nothing, Yeah. The 'top level' is syntactically and semantically different to the inner levels of Ocaml. (1) At the top level you can write a sequence of definitions or evaluate a sequence of expressions. This is not possible anywhere else. (2) If the definition/expression starts with a keyword you don't need to use ';;' before it. For example: let f x = x let g x = x * x ;; (* needed because .. *) f x * g x (* no keyword starts this *) ;; (* needed to force evaluation of expression NOW *) At the inner level, you cannot write let h x = let f x = x let g x = x * x ;; f x * g x ;; Inner expressions are evaluated 'entirely', not one at a time like the top level. So you must write this: let h x = let f x = x in let g x = x * x in f x * g x ;; (* end top level definition *) You use ';' for sequencing evaluations: print_endline "Hello"; print_endline "World" ;; This is a *single* expression evaluated, whereas print_endline "Hello" ;; print_endline "World" ;; is two evaluations. (Try this in the 'ocaml' interpreter). > when to use ( ), and things of > the like. It doesn't help that the compiler is completly naive when it > comes to Syntax Errors. The reason is: the parser is a Yacc tool which means it uses a LR parsing technique. When it can't parse something, it has no choice than to say 'syntax error'. Its an error, there's no way to say what the error is. One way around this in LR parsers is to include error productions in the grammar... that is, make the parser parse common errors. Another way, is to parse something more general than permitted first, then check constraints. This is certainly done with type checking for example. ------------------- 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