Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Read-only arrays ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-04-11 (05:55)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Read-only arrays ?
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