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 VAA11632; Sat, 1 May 2004 21:51:42 +0200 (MET DST) 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 VAA11955 for ; Sat, 1 May 2004 21:51:41 +0200 (MET DST) From: Alain.Frisch@ens.fr Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i41JpfSH004187 for ; Sat, 1 May 2004 21:51:41 +0200 Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.12.10/1.01.28121999) with ESMTP id i41JpeKx034621 ; Sat, 1 May 2004 21:51:40 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id i41JpcTw029142 ; Sat, 1 May 2004 21:51:39 +0200 (MET DST) X-Authentication-Warning: clipper.ens.fr: frisch owned process doing -bs Date: Sat, 1 May 2004 21:51:38 +0200 (MET DST) X-X-Sender: frisch@clipper.ens.fr Reply-To: Alain.Frisch@ens.fr To: skaller cc: caml-list Subject: Re: [Caml-list] Reading a large text file In-Reply-To: <1083439539.20722.93.camel@pelican.wigram> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-milter (http://amavis.org/) X-Miltered: at concorde with ID 4093FFCD.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; alain:01 frisch:01 caml-list:01 struct:01 mylist:01 mylist:01 immutable:01 struct:01 mutability:01 deconstruct:01 alain:01 mutable:01 mutable:01 sig:01 constructors:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 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). So you have to expose constructors explicitly (splice is one of them, but you probably want a simple Cons). -- Alain ------------------- 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