caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: David.Teller@univ-orleans.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Read-only arrays ?
Date: Wed, 11 Apr 2007 14:31:20 +0900 (JST)	[thread overview]
Message-ID: <20070411.143120.55511796.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <1176268090.27607.9.camel@Blefuscu>

From: David Teller <David.Teller@univ-orleans.fr>

> 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


  reply	other threads:[~2007-04-11  5:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-10 21:03 David Teller
2007-04-10 21:35 ` [Caml-list] " Martin Jambon
2007-04-10 21:57   ` Harrison, John R
2007-04-10 23:12     ` Martin Jambon
2007-04-11  5:08       ` David Teller
2007-04-11  5:31         ` Jacques Garrigue [this message]
2007-04-11  5:50           ` Jon Harrop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070411.143120.55511796.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=David.Teller@univ-orleans.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).