caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: Immutable arrays (modest Feature request)
@ 2000-01-13 19:45 ` Juergen Pfitzenmaier
  2000-01-14 18:09   ` Mark Hayden
  0 siblings, 1 reply; 6+ messages in thread
From: Juergen Pfitzenmaier @ 2000-01-13 19:45 UTC (permalink / raw)
  To: caml-list

I too would like to see immutable strings/arrays if they are faster than
their mutable siblings.

pfitzen




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Immutable arrays (modest Feature request)
  2000-01-13 19:45 ` Immutable arrays (modest Feature request) Juergen Pfitzenmaier
@ 2000-01-14 18:09   ` Mark Hayden
  2000-01-14 20:29     ` Markus Mottl
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Hayden @ 2000-01-14 18:09 UTC (permalink / raw)
  To: caml-list


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.

--Mark

Date: Thu, 13 Jan 2000 20:45:01 +0100
To:  caml-list@inria.fr
From:  Juergen Pfitzenmaier <pfitzen@informatik.uni-tuebingen.de>
Subject:  Re: Immutable arrays (modest Feature request)
Delivery-Date:  Fri Jan 14 00:00:39 2000
>
>I too would like to see immutable strings/arrays if they are faster than
>their mutable siblings.
>
>pfitzen
>




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Immutable arrays (modest Feature request)
  2000-01-14 18:09   ` Mark Hayden
@ 2000-01-14 20:29     ` Markus Mottl
  0 siblings, 0 replies; 6+ messages in thread
From: Markus Mottl @ 2000-01-14 20:29 UTC (permalink / raw)
  To: Mark Hayden; +Cc: OCAML

> 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"
operation:

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:

  http://miss.wu-wien.ac.at/~mottl/ocaml_sources/res/README

Regards,
Markus Mottl

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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Immutable arrays (modest Feature request)
  2000-01-12 22:06 ` Pierre Weis
@ 2000-01-12 22:35   ` Norman Ramsey
  0 siblings, 0 replies; 6+ messages in thread
From: Norman Ramsey @ 2000-01-12 22:35 UTC (permalink / raw)
  To: Pierre Weis; +Cc: ohl, caml-list

I would have used immutable strings in my last Caml program
had they been available.   I would like vectors as well (though I confess
I use them rarely).

N




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Immutable arrays (modest Feature request)
  2000-01-12 15:45 Thorsten Ohl
@ 2000-01-12 22:06 ` Pierre Weis
  2000-01-12 22:35   ` Norman Ramsey
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre Weis @ 2000-01-12 22:06 UTC (permalink / raw)
  To: ohl; +Cc: caml-list

> 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.
> 
> Cheers,
> -Thorsten
> -- 
> Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de
> http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]

It existed in the past in Caml for strings (named ropes) and vectors
(named segments). It has been removed since nobody used them ...

I'm not sure it is worth the additional complexity ...

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Immutable arrays (modest Feature request)
@ 2000-01-12 15:45 Thorsten Ohl
  2000-01-12 22:06 ` Pierre Weis
  0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Ohl @ 2000-01-12 15:45 UTC (permalink / raw)
  To: caml-list

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.

Cheers,
-Thorsten
-- 
Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de
http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-01-16 21:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <pfitzen@informatik.uni-tuebingen.de>
2000-01-13 19:45 ` Immutable arrays (modest Feature request) Juergen Pfitzenmaier
2000-01-14 18:09   ` Mark Hayden
2000-01-14 20:29     ` Markus Mottl
2000-01-12 15:45 Thorsten Ohl
2000-01-12 22:06 ` Pierre Weis
2000-01-12 22:35   ` Norman Ramsey

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).