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 WAA14053; Sat, 1 May 2004 22:40:19 +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 WAA14290 for ; Sat, 1 May 2004 22:40:18 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i41KeFSH013023 for ; Sat, 1 May 2004 22:40:16 +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 i41Ke9k2064491; Sun, 2 May 2004 06:10:10 +0930 (CST) Subject: Re: [Caml-list] Reading a large text file From: skaller Reply-To: skaller@users.sourceforge.net To: Alain.Frisch@ens.fr Cc: caml-list In-Reply-To: References: Content-Type: text/plain Message-Id: <1083444008.20722.135.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 02 May 2004 06:40:08 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40940B2F.000 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 alain:01 frisch:01 struct:01 mylist:01 mylist:01 immutable:01 struct:01 immutable:01 mutability:01 deconstruct:01 val:01 val:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 2004-05-02 at 05:51, Alain.Frisch@ens.fr wrote: > On 2 May 2004, skaller wrote: > > > 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*. > > Not quite. > > First, the "private" keyword should be used only in the signature, not the > structure, otherwise the implementation of the module has no special > right. Something like: > > module M : > sig type t = private *** end > = > struct type t = *** end Thanks for the correction. Also note I chose a *really bad name* when I called it 'splice': the intent was to construct a new list as stated, so I should have just called it 'concat'. Of course you could make a list with an actual splice mutator, but then it wouldn't be immutable. > Second, the client cannot create values of the "private" type. This is > not related at all with the mutability of the fields. It can only > deconstruct values (with pattern matching). Right. Well stated. Hmm .. module M : sig ?? type 'a t = private 'a list val uniq_cons: 'a t -> 'a -> 'a list val empty: unit -> 'a list end = struct type 'a t = 'a list let uniq_cons lst a = if List.mem a lst then lst else a::lst let empty () = [] end ;; ;; Syntax error: 'end' expected, the highlighted 'sig' might be unmatched Arggg.. what's wrong here? It has nothing to do with either private or type variables, and the above sig fails immediately in a module type statement too. -- 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