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 PAA15035; Fri, 9 Nov 2001 15:06:43 +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 PAA14762 for ; Fri, 9 Nov 2001 15:06:42 +0100 (MET) Received: from smtp2.cswv.com (smtp2.cswv.com [4.17.129.20]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fA9E6fn11626 for ; Fri, 9 Nov 2001 15:06:41 +0100 (MET) Received: from smtp2.cswv.com ([10.2.3.6]) by smtp2.cswv.com with Microsoft SMTPSVC(5.5.1877.197.19); Fri, 9 Nov 2001 09:06:35 -0500 Received: FROM exchange1.cswv.com BY smtp2.cswv.com ; Fri Nov 09 09:06:34 2001 -0500 Received: by exchange1.cswv.com with Internet Mail Service (5.5.2653.19) id ; Fri, 9 Nov 2001 09:10:10 -0500 Message-ID: From: "Krishnaswami, Neel" To: "'Franck'" , caml-list@inria.fr Subject: RE: [Caml-list] Great Beginner Date: Fri, 9 Nov 2001 09:10:00 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Franck [mailto:franck.collineau@francetelecom.com] wrote: > Hello! > I have written the following code: > let somme(x,n)= > for i=1 to i=n > do > x<-x+1 > done;; > > caml tel me that i is not define. What is the problem ? You have a couple of syntax errors. First, the syntax of a for-loop is "for i = 1 to n do done" Second, your assignment statement x <- x + 1 has the wrong syntax, and the wrong type. If you want to do an assignment, you need to use the (:=) operator, like this: x := 5 (:=) has the type 'a ref -> 'a -> unit, which means that the left hand side should be a reference, and the right hand side should be the value you want the reference to point to. However, when you write: x := x + 1 you will get a type error, because x has type int ref, and (+) has type int -> int -> int. So to do the addition you need to dereference the reference: let somme(x, n) = for i = 1 to n do x := !x + 1 done which has type int ref -> int -> unit. This doesn't look like a function I would want to write, but maybe you do. :) -- Neel Krishnaswami neelk@cswcasa.com ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr