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
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-12 (22:07)
From: Thorsten Ohl <ohl@h...>
Subject: Immutable arrays (modest Feature request)
I've always wondered why O'Caml has no notion of immutable arrays or
vectors.  (Mutable) Arrays are often inconvenient because callers and
callees must negotiate who is doing the copying.  A conservative
approach will do too many copies.

Semantically, a vector of size n would be a record with
labels 0,...,n-1 and with O(1) access.  One would initialize them from
a constant (e.g. let v = [{ 42; 137; 1789 }]), a list, an array, or a
function. Updates would be requested by [{ v with 2 = 2000 }] and most
of the Array and List library is useful for vectors.

I admit that this is theoretically not very exciting (except for the
question when the `with' must copy and when not), but rather useful.

Thorsten Ohl, Physics Department, TU Darmstadt -- [<=== PGP public key here]