English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: Immutable arrays (modest Feature request)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-01-16 (21:25)
From: Markus Mottl <mottl@m...>
Subject: Re: Immutable arrays (modest Feature request)
> 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"

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:


Markus Mottl

Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl