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 QAA31579; Wed, 15 Sep 2004 16:52:32 +0200 (MET DST) 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 QAA00412 for ; Wed, 15 Sep 2004 16:52:31 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8FEqTa2029141 for ; Wed, 15 Sep 2004 16:52:30 +0200 Received: from [192.168.1.200] (ppp202-133.lns1.syd3.internode.on.net [203.122.202.133]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i8FEqQOU046465; Thu, 16 Sep 2004 00:22:27 +0930 (CST) Subject: Re: [Caml-list] Confused From: skaller Reply-To: skaller@users.sourceforge.net To: Jon Harrop Cc: caml-list In-Reply-To: <200409151428.54124.jon@jdh30.plus.com> References: <41472EC6.2080007@gmx.net> <200409151428.54124.jon@jdh30.plus.com> Content-Type: text/plain Message-Id: <1095259945.27775.1034.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 16 Sep 2004 00:52:26 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4148572D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 val:01 val:01 stupid:01 demonstrate:01 'ocaml':01 newbies:01 'match':01 justified:01 9660:01 glebe:01 compiler:01 overloading:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 2004-09-15 at 23:28, Jon Harrop wrote: > How come this works: > > # let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1);; > val build : int -> float list = > # let test = 1. :: build 1000;; > val test : float list = ... > > But this does not: > > # let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1) in > let test = 1. :: build 1000;; > Syntax error > > Am I being stupid? The top level let is unrelated to the expression let/in. It just happens to use the same keyword. I'll change the keyword to demonstrate: toplet x = y;; let x = y in z;; The first form is a toplet statement, the second is an entirely unrelated expression statement. Note that toplet explicitly has side-effects -- it enriches the global environment with the symbol x. The expression statement has side-effects if y and z do OR if you are using the command line 'ocaml' program (it prints the type and value). Now rewriting your example: let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1) in toplet test = 1. :: build 1000;; you can see you've used a 'toplet' in an inner location where an expression is expected: let/in is an expression, toplet isn't. Basically this syntax is a 'hack' used by language designers, overloading related syntactic forms to avoid introducing new keywords and to make the language 'more intuitive' - which usually backfires on newbies and even experts at times. Such impurity is annoying, however a fully 'orthogonal' syntax may well be worse. For example seeing: int_match x with | 1 -> .. float_match x wth | 1.2 -> ... variant_match x with | True -> you can probably agree some 'pattern matching' in the compiler itself to discriminate these cases (and allow just plain 'match') is probably justified. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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