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 XAA29462; Thu, 18 Dec 2003 23:08:49 +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 XAA28974 for ; Thu, 18 Dec 2003 23:08:48 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from web40610.mail.yahoo.com (web40610.mail.yahoo.com [66.218.78.147]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id hBIM8kH08644 for ; Thu, 18 Dec 2003 23:08:46 +0100 (MET) Message-ID: <20031218220845.75406.qmail@web40610.mail.yahoo.com> Received: from [216.33.229.163] by web40610.mail.yahoo.com via HTTP; Thu, 18 Dec 2003 14:08:45 PST Date: Thu, 18 Dec 2003 14:08:45 -0800 (PST) From: Ker Lutyn Subject: Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 python's:01 lisp's:01 c's:01 iterator:01 iterator:01 0900,:01 cannasse:01 uploading:01 ocaml:01 nicolas:01 closure:01 rec:01 rec:01 node:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk How about: type 'a cont = Cont of ('a -> 'a cont) let apply c x = match c with Cont f -> f x let rec iterator c = function | Node l -> List.fold_left iterator c l | Leaf x -> apply c x On Thu, Dec 18, 2003 at 10:14:19AM +0900, Nicolas Cannasse wrote: > > 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. __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ ------------------- 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