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 DAA19117; Tue, 4 Mar 2003 03:49:31 +0100 (MET) 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 DAA19719 for ; Tue, 4 Mar 2003 03:49:29 +0100 (MET) Received: from ux9.sp.cs.cmu.edu (UX9.SP.CS.CMU.EDU [128.2.220.166]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id h242nST13197 for ; Tue, 4 Mar 2003 03:49:28 +0100 (MET) Received: from 12-227-100-158.client.attbi.com ([12.227.100.158]) by ux9.sp.cs.cmu.edu id aa29161; 3 Mar 2003 21:49 EST Received: from ecc by stratocaster.home with local (Exim 3.36 #1 (Debian)) id 18q2Ua-0006Oq-00 for ; Mon, 03 Mar 2003 21:49:20 -0500 Date: Mon, 3 Mar 2003 21:49:20 -0500 To: "caml-list@inria.fr" Subject: Re: [Caml-list] Strings as arrays or lists... Message-ID: <20030304024920.GA24512@stratocaster.home> Mail-Followup-To: "caml-list@inria.fr" References: <20030227223155.GA488@first.in-berlin.de> <20030302193437.A6487@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030302193437.A6487@pauillac.inria.fr> User-Agent: Mutt/1.4i From: "Eric C. Cooper" X-Spam: no; 0.00; caml-list:01 coercions:01 char:01 regexps:01 recursion:01 datatype:01 checksum:01 marshaling:01 buffer:01 debugging:01 analogous:01 arrays:01 ocaml:01 byte:01 marshal:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Mar 02, 2003 at 07:34:37PM +0100, Xavier Leroy wrote: > Actually, the list representation of strings is so repugnant that I > don't even want to include "explode" and "implode" coercions between > string and char list in the standard library. A standard library > should steer users away from algorithmically-inefficient code. By not > having implode and explode in the library, I hope OCaml programmers > will come to the realization that the proper way to operate on strings > is either via block operations (the String module, regexps, etc), or > by recursion on integer indices. I recently wrote some code that made use of char lists, and explode and implode came in handy. I needed to marshal a recursive datatype into a packet to be sent over a communication channel according to a protocol that imposed a specific format, including a length byte at the beginning and a checksum byte at the end. I could have made one pass over the data to compute the packet length, then a second pass marshaling it into a buffer. But it was very natural to just build up a list of bytes in a single traversal of the datatype. Then the length and checksum could easily be added to the beginning and the end, and the result written out. I used explode when I encountered string values at the leaves of the datatype. I didn't really need implode (I could just iterate output_byte over the final list), but it came in handy for dumping packets for debugging. I wasn't really using char lists as a representation of strings, but rather as a buffer-like data structure that just happened to need conversion to and from strings at certain points. As another poster pointed out, explode and implode are analogous to Array.to_list and Array.of_list, which don't seem to entice OCaml programmers down the path of algorithmic ineffiency. -- Eric C. Cooper e c c @ c m u . e d u ------------------- 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