From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id EE195BC88 for ; Thu, 10 Feb 2005 04:40:00 +0100 (CET) Received: from ptb-relay01.plus.net (ptb-relay01.plus.net [212.159.14.212]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j1A3e0hx008442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 10 Feb 2005 04:40:00 +0100 Received: from [80.229.56.224] (helo=chetara) by ptb-relay01.plus.net with esmtp (Exim) id 1Cz5BQ-000OdW-7n for caml-list@yquem.inria.fr; Thu, 10 Feb 2005 03:40:00 +0000 From: Jon Harrop Organization: University of Cambridge To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] String to list to string Date: Thu, 10 Feb 2005 03:41:46 +0000 User-Agent: KMail/1.7.1 References: <420ac293.30127b31.1fa8.0b02@smtp.gmail.com> In-Reply-To: <420ac293.30127b31.1fa8.0b02@smtp.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200502100341.46451.jon@jdh30.plus.com> X-Miltered: at concorde with ID 420AD790.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 char:01 char:01 iter:01 haskell:01 ...:98 frog:98 arbitrary:01 arbitrary:01 strings:01 strings:01 functions:01 functions:01 essentially:01 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 Thursday 10 February 2005 02:10, Juancarlo A=F1ez wrote: > Why aren't there functions in the standard library to convert strings to > lists of characters and back? Outrageously, the core library fails to provide an arbitrary number of=20 arbitrary functions. This exact question came up recently. The answer was=20 essentially: Why string -> char list and not string -> char array? Why stri= ng=20 =2D> char list and not string -> string list? And so on. If you want succinct implementations then I'd go for: let char_list_of_string s =3D let l =3D ref [] in String.iter (fun c -> l :=3D c :: !l) s; List.rev !l let string_of_char_list l =3D String.concat "" (List.map (String.make 1) l) > Haskell treats strings as lists of chars by default. I see an optimisation... =2D-=20 Dr Jon D Harrop, Flying Frog Consultancy Ltd.