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.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 10C56BC6E for ; Wed, 11 Apr 2007 07:55:05 +0200 (CEST) Received: from ptb-relay02.plus.net (ptb-relay02.plus.net [212.159.14.213]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3B5t4ul032028 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 11 Apr 2007 07:55:04 +0200 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay02.plus.net with esmtp (Exim) id 1HbVnL-0000Pz-PR for caml-list@yquem.inria.fr; Wed, 11 Apr 2007 06:55:04 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Read-only arrays ? Date: Wed, 11 Apr 2007 06:50:17 +0100 User-Agent: KMail/1.9.5 References: <509223F0BF55E74FA1247D17207E7A0C014E5043@orsmsx419.amr.corp.intel.com> <1176268090.27607.9.camel@Blefuscu> <20070411.143120.55511796.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20070411.143120.55511796.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200704110650.17854.jon@ffconsultancy.com> X-Miltered: at concorde with ID 461C7838.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; read-only:01 arrays:01 arrays:01 coalescing:01 abstraction:01 syntax:01 syntaxes:01 ocaml:01 syntax:01 vectors:01 matrices:01 hash:01 ocaml:01 frog:98 wrote:01 On Wednesday 11 April 2007 06:31, Jacques Garrigue wrote: > If your board is already abstract, why convert it to arrays? Yes, the API is the problem and not the lack of immutable arrays. Just pull the array functions that you use into the Board module, e.g. Board.init. Essentially, you'll be coalescing an immutable array implementation with your Board module. You may also want to add a "where" function that accepts a continuation and applies it to the board with one element changed, undoing the change upon return. I find that to be a useful idiom. > This is actually the strongest argument against immutable arrays: they > are just an abstraction over arrays, that you can easily make yourself > when needed. I disagree. Syntax is important enough that strings and arrays have abbreviated (and clearer) syntaxes for getting and setting elements in OCaml. You cannot add that to your own immutable array implementation (unless you use macros as well, in which case you've forked the language itself). F# is very nice in this respect, allowing the a.[i] syntax to be overloaded so that strings, arrays, vectors, matrices, maps, hash tables and so on can all share the same syntax. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists