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 RAA21171; Fri, 9 Apr 2004 17:04:59 +0200 (MET DST) 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 RAA21209 for ; Fri, 9 Apr 2004 17:04:58 +0200 (MET DST) Received: from mailhost.trusted-logic.fr (mailhost.trusted-logic.fr [194.250.150.5]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i39F4vYM022174 for ; Fri, 9 Apr 2004 17:04:57 +0200 Received: from wight.trusted-logic.fr (wight.trusted-logic.fr [192.168.1.210]) by mailhost.trusted-logic.fr (Postfix) with ESMTP id 6F9B9177; Fri, 9 Apr 2004 17:04:57 +0200 (CEST) Received: from hoedic (hoedic.trusted-logic.fr [192.168.3.2]) by wight.trusted-logic.fr (Postfix) with SMTP id 55338713C0; Fri, 9 Apr 2004 17:04:57 +0200 (CEST) Message-ID: <003301c41e45$0f1de290$0203a8c0@hoedic> From: =?iso-8859-1?Q?Correnson_Lo=EFc?= To: Cc: "Ocaml" References: <20040409110138.GA1333@first.in-berlin.de><16502.38522.179048.194250@gargle.gargle.HOWL><16502.42309.605598.795600@gargle.gargle.HOWL> <16502.46797.938811.422113@gargle.gargle.HOWL> Subject: Re: [Caml-list] String.map => Question to the OCaml-team Date: Fri, 9 Apr 2004 17:12:22 +0200 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-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ocaml-team:01 char:01 char:01 libs:01 tail-rec:01 int:01 rec:01 lib:01 unit:03 unit:03 string:03 string:03 iter:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 219 Have also a look at Array.iteri : It allows to not use a for, nor an extra ref. It shall be possible to have in lib: String.iter : (char -> unit) -> string -> unit String.iteri : (int ->char -> unit) -> string -> unit Then: let map f s = let t = String.copy s in ( String.iteri (fun i c -> t.[i] <- f c) s ; t ) However, without extra libs nor for, but with a tail-rec function : let map f s = let rec iteri i n t = if i