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 CAA15597; Thu, 18 Dec 2003 02:15:27 +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 CAA15220 for ; Thu, 18 Dec 2003 02:15:26 +0100 (MET) Received: from smtp.siren.ocn.ne.jp (siren.ocn.ne.jp [211.129.13.170]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBI1FGH23582; Thu, 18 Dec 2003 02:15:18 +0100 (MET) Received: from PWARP (p3167-ipad07kyoto.kyoto.ocn.ne.jp [221.189.194.167]) by smtp.siren.ocn.ne.jp (Postfix) with SMTP id 97F5D1C34; Thu, 18 Dec 2003 10:15:10 +0900 (JST) Message-ID: <004c01c3c504$62407b80$0274a8c0@PWARP> From: "Nicolas Cannasse" To: "Pierre Weis" , "Falk Hueffner" Cc: References: <200312171914.UAA00389@pauillac.inria.fr> Subject: Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml Date: Thu, 18 Dec 2003 10:14:19 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 python's:01 lisp's:01 c's:01 pierre:01 weis:01 iterator:01 iterator:01 cannasse:01 ocaml:01 ocaml:01 nicolas:01 nicolas:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > [...] > > 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. > > Very interesting: please give us the code corresponding to this > example, in order for us to realize how the full power of the "yield" > operator helps to solve this problem. > > Pierre Weis > One simple sample is tree walking : "if there was yield in ocaml" type 'a tree = | Node of 'a tree list | Leaf of 'a let rec iterator = function | Node l -> List.iter iterator l | Leaf x -> yield x Doing it using a closure is more difficult, since we need to reproduce the stack using a data structure. That goes of course for all recursive data structures. Nicolas Cannasse ------------------- 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