From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 157E9BC69 for ; Wed, 11 Apr 2007 07:31:24 +0200 (CEST) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3B5VMKW018651 for ; Wed, 11 Apr 2007 07:31:23 +0200 Received: from localhost (millas [172.16.30.29]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id l3B5VKYW014930; Wed, 11 Apr 2007 14:31:20 +0900 (JST) Date: Wed, 11 Apr 2007 14:31:20 +0900 (JST) Message-Id: <20070411.143120.55511796.garrigue@math.nagoya-u.ac.jp> To: David.Teller@univ-orleans.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] Read-only arrays ? From: Jacques Garrigue In-Reply-To: <1176268090.27607.9.camel@Blefuscu> References: <509223F0BF55E74FA1247D17207E7A0C014E5043@orsmsx419.amr.corp.intel.com> <1176268090.27607.9.camel@Blefuscu> X-Mailer: Mew version 4.0.69 on Emacs 22.0.50 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 461C72AA.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; read-only:01 arrays:01 univ-orleans:01 abstracted:01 arrays:01 mutable:01 abstraction:01 literals:01 abstract:01 caml-list:01 functions:01 immutable:01 strings:01 argument:02 defined:02 From: David Teller > In my case, I'm writing a small board game my students will need to > complete in an assignment. So, I can trust that, if something can go > wrong, they'll find a way to make it happen. > > Essentially, the board is a matrix, abstracted in a module. > > Among other things, module Board provides > * a type Board.square of squares > * a type Board.t of boards (internally defined as a Board.square array > array) > * a conversion function Board.to_array : Board.t -> Board.square array > array (a copy function for the matrix) > * a conversion function Board.from_array : Board.square array array -> > Board.t (a copy function for the matrix) > > While performance is hardly critical, it's intellectually unsatisfying > to have and copy the whole board each time the borders of the module are > crossed, just to ensure that my students won't do anything wrong enough > to break the module. If your board is already abstract, why convert it to arrays? You could provide the right access functions. Or is it because you want to be able to update it destructively: then you need mutable arrays. If you don't care at all about performance, using lists of lists is yet another option. This is actually the strongest argument against immutable arrays: they are just an abstraction over arrays, that you can easily make yourself when needed. This is more cumbersome with strings, as we use literals everywhere. Jacques Garrigue