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 PAA29275; Wed, 15 Sep 2004 15:51:59 +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 PAA29136 for ; Wed, 15 Sep 2004 15:51:58 +0200 (MET DST) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8FDptDC019216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 15 Sep 2004 15:51:58 +0200 Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.13.1/8.12.11) with ESMTP id i8FDpiJb027804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Sep 2004 08:51:51 -0500 (CDT) Date: Wed, 15 Sep 2004 09:01:37 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Jon Harrop cc: caml-list@inria.fr Subject: Re: [Caml-list] Confused In-Reply-To: <200409151428.54124.jon@jdh30.plus.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 414848FB.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 val:01 val:01 stupid:01 ocaml:01 ocaml:01 int:01 rec:01 rec:01 sep:01 syntax:02 syntax:02 float:02 float:02 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 15 Sep 2004, 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 What you want to do is: let test = let rec build = funcion 0 -> [] | n -> 1e-6 :: build (n-1) in 1. :: build 1000 ;; "let var = expression" is not, itself, and expression. It's a statement. Ocaml does, in fact, have statements and not just expressions. The let/in construct is: "let var = expression in expression" is an expression- but it requires the stuff to the right of the 'in' keyword to also be an expression. This means that it can be another let/in expression, but not statements like "let var = expression". The solution, then, is to move the let/in definition down into the expression part of the statement- i.e., after the equals sign. Thus my counter-example. > Am I being stupid? No- just confused on a subtle point of Ocaml syntax. -- "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