Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Multi-keyed lookup table?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: ijtrotts@u...
Subject: Re: [Caml-list] Array.filter (was Multi-keyed lookup table?)
On Sat, Aug 09, 2003 at 10:57:20AM -0600, Matt Gushee wrote:
> On Sat, Aug 09, 2003 at 10:36:06AM +0200, Jean-Baptiste Rouquier wrote:
> > >BTW, why isn't there an Array.filter function?
> > There is a lot of such general purpose functions that one would like to have
> > already implemented. But having all of these in the standard library would
> > make it less readable.
> 
> Sure. I just thought that lists and arrays are rather similar data
> structures, and to the extent that they are similar, their respective
> modules should have similar APIs.

It might help to create a file (mods.ml) with your favorite additions 
and modifications to the standard library.  Then you can open Mods
in any files where the modifications are needed.

# module Array = struct
   include Array
   let filter f a = Array.init (Array.length a) (fun i -> f a.(i))
  end;;
# Array.filter (fun x -> x * x) [| 1;2;3 |];;     
- : int array = [|1; 4; 9|]

Hope this helps,
Issac

-- 
Issac Trotts
Programmer
Center for Neuroscience
University of California, Davis 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners