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 VAA10712; Sat, 1 May 2004 21:25:50 +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 VAA10795 for ; Sat, 1 May 2004 21:25:49 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i41JPkEV014944 for ; Sat, 1 May 2004 21:25:47 +0200 Received: from [192.168.1.200] (ppp116-155.lns1.syd2.internode.on.net [150.101.116.155]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i41JPdk2053574; Sun, 2 May 2004 04:55:40 +0930 (CST) Subject: Re: [Caml-list] Reading a large text file From: skaller Reply-To: skaller@users.sourceforge.net To: Richard Jones Cc: caml-list In-Reply-To: <20040501180508.GA16958@redhat.com> References: <20040428152813.47355.qmail@web60608.mail.yahoo.com> <20040501154351.GA5218@online.fr> <20040501180508.GA16958@redhat.com> Content-Type: text/plain Message-Id: <1083439539.20722.93.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 02 May 2004 05:25:39 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4093F9BA.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 2004:99 0400,:01 immutable:01 struct:01 mylist:01 mylist:01 immutable:01 preserving:01 9660:01 glebe:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 2004-05-02 at 04:05, Richard Jones wrote: > On Sat, May 01, 2004 at 11:43:51AM -0400, Rahul Siddharthan wrote: > The short answer is no, because in OCaml (unlike in LISP) lists are > immutable. > However, OCaml is a practical language and so allows you to create a > mutable cons structure if you so desire. eg: It can now do slightly better than that. It is possible to use the new 'private' keyword to *guard* your mutable list. module MList = struct type 'a mylist = private { head : 'a; mutable tail : 'a mylist option; } .. let splice a b = ...(* makes a new mylist of a @ b *) end Here, lists are immutable *publically*. However the splice function provides a concatenation of two ordinary lists into a mylist in 1 pass, with O(1) stack usage and the result is in forward order, not reversed. The list is still immutable! You can't modify it. The mutable field is only used during construction to append to the end, preserving the forward ordering. Its possible for C language implementations to do that kind of thing right now for actual Ocaml lists. But now you can play the game in Ocaml. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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