From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 12B35BC8E for ; Tue, 15 Feb 2005 14:34:17 +0100 (CET) Received: from ux9.sp.cs.cmu.edu (UX9.SP.CS.CMU.EDU [128.2.220.166]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j1FDYGrR023831 for ; Tue, 15 Feb 2005 14:34:16 +0100 Received: from c-24-3-154-200.client.comcast.net ([24.3.154.200]) by ux9.sp.cs.cmu.edu id aa30067; 15 Feb 2005 8:34 EST Received: from ecc by stratocaster.home with local (Exim 4.34) id 1D12q3-0004wU-EJ; Tue, 15 Feb 2005 08:34:03 -0500 Date: Tue, 15 Feb 2005 08:34:03 -0500 To: Richard Jones Cc: Aaron Bohannon , caml-list@yquem.inria.fr, ocaml-lib-devel@lists.sourceforge.net Subject: Re: [Caml-list] String to list to string Message-ID: <20050215133403.GB18971@localhost> Mail-Followup-To: Richard Jones , Aaron Bohannon , caml-list@yquem.inria.fr, ocaml-lib-devel@lists.sourceforge.net References: <420ac293.30127b31.1fa8.0b02@smtp.gmail.com> <200502100341.46451.jon@jdh30.plus.com> <42114D83.5000905@cis.upenn.edu> <20050215103316.GA21083@furbychan.cocan.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050215103316.GA21083@furbychan.cocan.org> User-Agent: Mutt/1.5.6+20040907i From: "Eric C. Cooper" X-Miltered: at nez-perce with ID 4211FA58.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 val:01 char:01 val:01 char:01 rec:01 rec:01 functions:01 string:03 string:03 let:03 let:03 tue:06 fold:06 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Tue, Feb 15, 2005 at 10:33:16AM +0000, Richard Jones wrote: > If you can suggest suitable fold_left and fold_right functions, then > they can be added to ExtLib. Here's what I use: val string_fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a val string_fold_right : (char -> 'a -> 'a) -> 'a -> string -> 'a let string_fold_left f init str = let n = String.length str in let rec loop i result = if i = n then result else loop (i + 1) (f result str.[i]) in loop 0 init let string_fold_right f init str = let n = String.length str in let rec loop i result = if i = 0 then result else let i' = i - 1 in loop i' (f str.[i'] result) in loop n init -- Eric C. Cooper e c c @ c m u . e d u