[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Michal Moskal <malekith@p...> |
| Subject: | Re: [Caml-list] Array.filter (was Multi-keyed lookup table?) |
On Sat, Aug 09, 2003 at 11:48:51AM -0700, ijtrotts@ucdavis.edu wrote:
> # 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|]
This is map, not filter. Writing filter is more difficult, since you
need to first make list of results and then put them into array (or use
Obj.magic tricks).
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
-------------------
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