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 XAA09001; Sun, 29 Apr 2001 23:12:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA08402 for caml-list@pauillac.inria.fr; Sun, 29 Apr 2001 23:12:10 +0200 (MET DST) 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 AAA04162 for ; Fri, 27 Apr 2001 00:33:55 +0200 (MET DST) Received: from localhost.localdomain (jimbo61.zip.com.au [202.7.88.61]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f3QMXo513567 for ; Fri, 27 Apr 2001 00:33:51 +0200 (MET DST) Received: from ozemail.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id IAA31768; Fri, 27 Apr 2001 08:20:30 +1000 Message-ID: <3AE89F2E.622B7EFC@ozemail.com.au> Date: Fri, 27 Apr 2001 08:20:30 +1000 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Mark Seaborn CC: caml-list@inria.fr Subject: Re: [Caml-list] two unrelated questions References: <200104252108.OAA02055@smtp2-cm.mail.eni.net> <873davha5b.fsf@argbg34.argonet.co.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Mark Seaborn wrote: > Another way of doing it is to CPS-convert the fold function to get > something like: > > let rec foldc kons knil l = match l with > | [] -> knil > | x::xs -> kons x knil (fun rest -> foldc kons rest xs) > This is more powerful than fold, but also harder to understand, You're not kidding, on both counts :-) It's also 'ugly', because it only works for lists, but this is only because you hard coded the destructor. Passing it as an argument: let rec foldc remove kons knil l = match remove l with | (_,None) -> knil | (xs,Some x) -> kons x knil (fun rest -> foldc remove kons rest xs) let foldc_list = foldc (fun l -> match l with | [] -> l,None | x::xs -> xs,Some x) It's a pity there is no such destructor for a Hashtbl. [All C++ STL data structures have read iterators, which amount to destructors] -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr