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 UAA00336; Fri, 9 Apr 2004 20:29:33 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA00504 for ; Fri, 9 Apr 2004 20:29:30 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i39IUPjq025128 for ; Fri, 9 Apr 2004 20:30:25 +0200 Received: from warp (chateaudeau-4-82-225-176-25.fbx.proxad.net [82.225.176.25]) by postfix3-2.free.fr (Postfix) with SMTP id 70BDCC4DD; Fri, 9 Apr 2004 20:29:29 +0200 (CEST) Message-ID: <004301c41e60$377f4d80$19b0e152@warp> From: "Nicolas Cannasse" To: , References: <20040409110138.GA1333@first.in-berlin.de> <16502.38522.179048.194250@gargle.gargle.HOWL> <16502.42309.605598.795600@gargle.gargle.HOWL> <20040409145652.GB27343@gaia.cc.gatech.edu> Subject: Re: [Caml-list] String.map => Question to the OCaml-team Date: Fri, 9 Apr 2004 20:26:46 +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.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 ocaml-team:01 for':99 char:01 char:01 blit:01 modeled:01 haskell:01 abominable:01 generic:01 bigarrays:01 hastables:01 extlib:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 222 > > > Note there is a `for' construct in ocaml: > > > > > > ====================================================================== > > > let string_map (f: char -> char) (s: string) : string = > > > let t = String.copy s in > > > for i = 0 to String.length s - 1 do t.[i] <- f s.[i] done; > > > t > > > ====================================================================== > > > > > > and this is slightly faster than your implementation (by 10%). > > > > Why not just use String.blit, as provided by the standard library? > > > > Fernando > > > The whole thing would be a lot nicer if there were a String.init > > init : int -> (int -> char) -> string > > obviously modeled on Array.init, since the OCaml designers had enough good > sense not to follow Haskell and make strings lists (or provide abominable > built in string -> char list functions). I wonder how usefulthis is in > typical string manipulation? I guess I find other ways to do things... > > It would of course be nice if we had the oft discussed generic polymorphism > so that we could take better advantage of the similarity of strings and arrays > (and bigarrays and hastables and ...) than we can now. Bazaar to Cathedral, > anyone home? :-) Look at ExtLib :-) we added String.init and we have Enum module which can play with String as Array of chars without actually allocating an array of chars. http://ocaml-lib.sf.net Of course generics would add more sugar into our everyday caml coffee. Regards, 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