Browse thread
[Caml-list] Frustrated Beginner
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2003-12-23 (17:36) |
From: | Brian Hurt <bhurt@s...> |
Subject: | Re: [Caml-list] Frustrated Beginner |
On Tue, 23 Dec 2003, Sven Luther wrote: > On Tue, Dec 23, 2003 at 11:11:19AM -0500, Brian Hurt wrote: > > > My biggest source of problems seems to be the syntax. I'm totally > > > confused as far as ; vs ;; vs nothing, when to use ( ), and things of > > > the like. > > > > This took some rethinking on my part as well. The trick is to remember > > that ';' is an operator, like '+' and '.' are. Actually, the best > > comparison is with the comma operator in C. If the type of '+' is int -> > > int -> int ('+' takes two int parameters and returns an int), then the > > type of the ';' operator is unit -> 'a -> 'a (or more correctly, 'a -> 'b > > -> 'b). One you start thinking of ';' as an operator and not a statement > > seperator, it becomes more obvious that an ocaml function body is simply a > > single expression, and not a series of statements. ';;' is more close to > > what ';' in most languages mean- it's what ends an expression. > > Mmm, not really convinced. For me ;, is a shortcut for : > > let () = ... in Or more accurately let _ = ... in ... > > Actually, i believe that both constructs result in the exact same code. > > That said, i guess it would not really help someone coming from the > imperative world, and not used to the let ... = ... in construct. Yep. The change in thinking is that ';' doesn't seperate statements, but combines two expressions into one expression. Your understanding is more technically correct, but I was trying to draw analogies to '+' and ','. -- "Usenet is like a herd of performing elephants with diarrhea -- massive, difficult to redirect, awe-inspiring, entertaining, and a source of mind-boggling amounts of excrement when you least expect it." - Gene Spafford Brian ------------------- 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