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 OAA01427; Fri, 14 Sep 2001 14:49:00 +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 OAA01541 for ; Fri, 14 Sep 2001 14:48:59 +0200 (MET DST) Received: from uni-sb.de (uni-sb.de [134.96.252.33]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f8ECmwf00058 for ; Fri, 14 Sep 2001 14:48:59 +0200 (MET DST) Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.252.31]) by uni-sb.de (8.11.6/2001082200) with ESMTP id f8ECmdP23647; Fri, 14 Sep 2001 14:48:39 +0200 (CEST) Received: from mail.cs.uni-sb.de (IDENT:9U48kssSyT1qIlBb0tD65VR3E32/lo7R@mail.cs.uni-sb.de [134.96.254.200]) by cs.uni-sb.de (8.11.6/2001081600) with ESMTP id f8ECmcd20961; Fri, 14 Sep 2001 14:48:38 +0200 (CEST) Received: from ps.uni-sb.de (grizzly.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.11.6/2001082200) with ESMTP id f8ECmao24111; Fri, 14 Sep 2001 14:48:36 +0200 (CEST) X-Authentication-Warning: email: Host grizzly.ps.uni-sb.de [134.96.186.68] claimed to be ps.uni-sb.de Received: from ps.uni-sb.de (zoidberg.ps.uni-sb.de [134.96.186.121]) by ps.uni-sb.de (8.11.2/8.11.0) with ESMTP id f8ECmaJ00831; Fri, 14 Sep 2001 14:48:36 +0200 Message-ID: <3BA1FCA4.9B1CA56@ps.uni-sb.de> Date: Fri, 14 Sep 2001 14:48:36 +0200 From: Andreas Rossberg Organization: =?iso-8859-1?Q?Universit=E4t?= des Saarlandes X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.3-12 i686) X-Accept-Language: de, en MIME-Version: 1.0 To: caml-list@inria.fr CC: Marco Maggesi Subject: Re: [Caml-list] mutable lists References: <87heu67ysf.fsf@sisiphos.math.unifi.it> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Marco Maggesi wrote: > > I noticed that OCaml do not have a library for mutable lists as, say, > Lisp or Scheme where most procedure that operate on lists have both > "functional" and "destructive" variants (like `append' and `append!'). > Is there any special theoretical reason for that? Mainly that functional lists are considered nicer and much easier to use (and thus more likely to be used right). Moreover, like all functional data structures, they are persistent, ie. you can have multiple versions of the same list or sublist simultanously. > One more question about phantom types that are discussed in a parallel > thread in these days. Is it possible to use phantom types to prevent > destructive operation on some lists? Yes. For example, Matthias Blume's ML encoding of the C type system I already mentioned in another post encodes C's constness annotations. The basic idea is to have phantom types type ro (* read-only *) type rw (* read/write *) and make your (mutable) list type polymorphic over them: type ('a,'r) list Then you can specify operations in the signature as follows: val nil : ('a,'r) list val cons : 'a -> ('a,'r) list -> ('a,'r) list val length : ('a,'r) list -> int val set_tail : ('a,rw) list -> ('a,rw) list -> unit val hash : ('a,ro) list -> int This prohibits destructively modifying the tail of a read-only list from the outside as well as using a mutable list for hashing, while length applies to any sort of list. - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de "Computer games don't affect kids; I mean if Pac Man affected us as kids, we would all be running around in darkened rooms, munching magic pills, and listening to repetitive electronic music." - Kristian Wilson, Nintendo Inc. ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr