caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [NEWBIE] is there an in-place map?
@ 2008-01-02 16:52 Kuba Ober
  2008-01-02 17:00 ` [Caml-list] " Jean-Christophe Filliâtre
  2008-01-02 17:26 ` Edgar Friendly
  0 siblings, 2 replies; 7+ messages in thread
From: Kuba Ober @ 2008-01-02 16:52 UTC (permalink / raw)
  To: caml-list

I need functionality of map, but done in such a way that the output array
is given as the argument, not as a return value. The closest I could get was

let inplace_map f a b = Array.blit (map f a) 0 b 0 (Array.length a)

Arrays a and b are of the same size.
This seems very inelegant.

One could use an adapter function and iteri, but that adds very noticeable 
overhead, and doesn't seem too elegant either.

let inplace_map f a b = Array.iteri (fun i src -> b.(i) <- f src; ()) a

There must be a better way of doing it, right? The given here is that the 
arrays a and b are there to stay, so we have to use them in-place.

Cheers, Kuba


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

end of thread, other threads:[~2008-01-03 16:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-02 16:52 [NEWBIE] is there an in-place map? Kuba Ober
2008-01-02 17:00 ` [Caml-list] " Jean-Christophe Filliâtre
2008-01-02 17:06   ` Brian Hurt
2008-01-02 17:26 ` Edgar Friendly
2008-01-02 17:36   ` Brian Hurt
2008-01-02 19:20     ` Edgar Friendly
2008-01-03 16:01       ` Kuba Ober

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