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 LAA06447; Wed, 17 Dec 2003 11:36:03 +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 LAA06278 for ; Wed, 17 Dec 2003 11:36:01 +0100 (MET) Received: from mx5.informatik.uni-tuebingen.de (mx5.Informatik.Uni-Tuebingen.De [134.2.12.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBHAa1X22188 for ; Wed, 17 Dec 2003 11:36:01 +0100 (MET) Received: from localhost (loopback [127.0.0.1]) by mx5.informatik.uni-tuebingen.de (Postfix) with ESMTP id A498D120 for ; Wed, 17 Dec 2003 11:36:00 +0100 (NFT) Received: from mx3.informatik.uni-tuebingen.de ([134.2.12.26]) by localhost (mx5 [134.2.12.32]) (amavisd-new, port 10024) with ESMTP id 30872-02 for ; Wed, 17 Dec 2003 11:35:59 +0100 (NFT) Received: from juist (semeai [134.2.15.66]) by mx3.informatik.uni-tuebingen.de (Postfix) with ESMTP id F303A134 for ; Wed, 17 Dec 2003 11:35:58 +0100 (NFT) Received: from falk by juist with local (Exim 3.36 #1 (Debian)) id 1AWZ26-0000Ee-00 for ; Wed, 17 Dec 2003 11:35:58 +0100 X-Face: "iUeUu$b*W_"w?tV83Y3*r:`rh&dRv}$YnZ3,LVeCZSYVuf[Gpo*5%_=/\_!gc_,SS}[~xZ wY77I-M)xHIx:2f56g%/`SOw"Dx%4Xq0&f\Tj~>|QR|vGlU}TBYhiG(K:2 <203E10E3-2FF3-11D8-A94A-000393CFE6B8@spy.net> <200312162230.23322.ijtrotts@ucdavis.edu> From: Falk Hueffner Date: 17 Dec 2003 11:35:58 +0100 In-Reply-To: <200312162230.23322.ijtrotts@ucdavis.edu> Message-ID: <87y8tbvii9.fsf@student.uni-tuebingen.de> User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (cabbage) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new (McAfee AntiVirus) at informatik.uni-tuebingen.de X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 python's:01 lisp's:01 c's:01 falk:01 hueffner:01 falk:01 hueffner:01 ijtrotts:01 incr:01 val:01 val:01 ocaml:01 int:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk ijtrotts@ucdavis.edu writes: > Why not do this: > > # let rec number() = > let i=ref(-1) in fun() -> > incr i; > !i, if !i mod 2 = 0 then "Even" else "Odd";; > val number : unit -> unit -> int * string = > # let n=number();; > val n : unit -> int * string = > # Array.init 10 (fun _ -> n());; > - : (int * string) array = > [|(0, "Even"); (1, "Odd"); (2, "Even"); (3, "Odd"); (4, "Even"); (5, "Odd"); > (6, "Even"); (7, "Odd"); (8, "Even"); (9, "Odd")|] This only works for simple examples. Try for example writing a function which successively yields all possible moves for a chess board. The "yield" operator really helps there. -- Falk ------------------- 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