From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA25291 for caml-redistribution; Sun, 16 Jan 2000 22:25:14 +0100 (MET) 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 VAA24513 for ; Fri, 14 Jan 2000 21:31:37 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id VAA00515 for ; Fri, 14 Jan 2000 21:31:36 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id VAA15875; Fri, 14 Jan 2000 21:29:58 +0100 (MET) From: Markus Mottl Message-Id: <200001142029.VAA15875@miss.wu-wien.ac.at> Subject: Re: Immutable arrays (modest Feature request) To: hayden@pa.dec.com (Mark Hayden) Date: Fri, 14 Jan 2000 21:29:55 +0100 (MET) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <200001141809.KAA04904@src-mail.pa.dec.com> from "Mark Hayden" at Jan 14, 2000 10:09:44 AM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: weis > You can write your own immutable arrays in Ocaml. > See for instance util/arrayf.{ml,mli} in Ensemble, > which is an implementation of functional arrays. > > http://www.cs.cornell.edu/Info/Projects/Ensemble/ > > Of course, there is no syntactic sugar for the > constructors and Array.get operation. Although, to my knowledge, you cannot use the syntactic sugar for constructors, you can indeed have it for the "Array.get" and "Array.set" operation: What OCaml actually does when translating "ar.(i)" is that it calls "Array.get ar i", where "Array" may be bound to any module you want. When the flag "-unsafe" is specified to the compiler, it will use "Array.unsafe_get ar i" instead. The same applies to "Array.set" and "Array.unsafe_set". As long as you provide for both implementations, there should be no problems. However, it might then become difficult to use the standard arrays, because you would have to rebind them to "Array" again each time you need them. But be aware that modules can also be rebound locally as in: let foo n = let module Array = StdArray in ... If you need more details on this, read the README in my distribution of automatically resizing arrays on: http://miss.wu-wien.ac.at/~mottl/ocaml_sources/res/README Regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl