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 HAA27229; Tue, 23 Dec 2003 07:13:04 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA27182 for ; Tue, 23 Dec 2003 07:13:03 +0100 (MET) Received: from out2.smtp.messagingengine.com (out2.smtp.messagingengine.com [66.111.4.26]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBN6D1v16167 for ; Tue, 23 Dec 2003 07:13:01 +0100 (MET) X-Sasl-enc: Ht3FN6sHV9IrFH6vq/DkmQ 1072159865 Received: from [192.168.1.101] (user224.net229.nc.sprint-hsd.net [65.173.93.224]) by mail.messagingengine.com (Postfix) with ESMTP id E6FF2488312; Tue, 23 Dec 2003 01:11:04 -0500 (EST) In-Reply-To: <20031223053451.GB1145@swordfish> References: <1072152186.59938.30.camel@tylere> <29911.24.6.3.124.1072153159.squirrel@www.cs.fiu.edu> <1072152186.59938.30.camel@tylere> <20031223053451.GB1145@swordfish> Mime-Version: 1.0 (Apple Message framework v609) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit Cc: caml-list@inria.fr From: Tyler Eaves Subject: Re: [Caml-list] Frustrated Beginner Date: Tue, 23 Dec 2003 01:11:08 -0500 To: Matt Gushee X-Mailer: Apple Mail (2.609) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 gushee:01 semicolons:01 semicolon:01 semicolon:01 model:01 foo:01 endline:01 endline:01 foo:01 compiler:01 ocaml:01 ocaml:01 lisp:01 syntax:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Dec 23, 2003, at 12:34 AM, Matt Gushee wrote: > >> So why is O'Caml giving me so much trouble? > > Do you have any previous experience with functional programming (FP), > or > have you studied FP in school? If not, then you're learning both a new > syntax and a very different programming paradigm at once, so you should > expect a steep learning curve. But I think if you stick with it, after > a > while it will all start to make sense, and you'll be glad you made the > effort. Not much, a (very) little Lisp. Not really enough to 'get it'. > >> I've been trying to pick it up for about a week now, read various >> online tutorials. > > http://www.merjis.com/richj/computers/ocaml/tutorial/ This is the one I've gotten the most out of. >> My biggest source of problems seems to be the syntax. I'm totally >> confused as far as ; vs ;; vs nothing, ... > > Yes, that is a bit tricky. You've undoubtedly read explanations of the > semicolons, but sometimes it helps if you get the same information > again > in slightly different terms, so let me try: > > * A double semicolon ends a "sentence"--that is, it terminates a > top-level construct such as a function definition--but not nested > function definitions, because they're not "sentences," they're > "phrases". > > You can omit ;; in most cases, but I would suggest at first using > it everywhere it is allowed. When you omit the ;; and there is a > syntax error in your code, the compiler often goes many lines past > the real trouble spot before it detects an error, so using ;; > everywhere can narrow down your search. > > * The single semicolon is perhaps a bit harder to understand, but I > think it helps to keep in mind that OCaml is basically a functional > language, yet it also supports imperative programming. Being > functional means that there are no statements per se. It's all > about > evaluating expressions, and *every* expression returns a value. > However, there are expressions that are functionally equivalent to > statements. In order to conform to the functional model, they have > to return a value, but there is no useful value to return. So they > return the unit value, '()'. Okay, that helps. > Basically, whenever you are programming imperatively--when you have > one of these pseudo-statements that return (), and when it this > imperative phrase is not the final result of a function, you need > to > separate it from the following phrase with a single semicolon. A > simple example: > > match foo with > | None -> print_endline "Nothing"; "" > | Some x -> print_endline x; x If I understand the match syntax correctly, in this case, x takes the value of foo? > This expression returns a string, but before returning, you want to > print a message. Printing functions, of course, return (). > > Hope this helps a bit. Best of luck to you It does, quite a bit. Thanks to everyone else too, I've already gotten something like 11 replies in an hour and a half :) ------------------- 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