[
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: | Jean-Baptiste Rouquier <jean-baptiste.rouquier@e...> |
| Subject: | Re: [Caml-list] Array.filter |
I didn't think I would have any answers ! I prefer reading "worl domination
thread", even if I don't have time to help for the moment. Perhaps the
really missing thing is one guy to coordinate the work.
I have a wish along #unload : the symetric of open, even if the [open] scope
is the current struct. So we can [open] a module in the main file, and
[close] it in the middle of the same file.
> It might help to create a file (mods.ml) with your favorite additions
>and modifications to the standard library.
I called it Complements in my precedent mail.
let filter test a =
let result = (Array.fold_left
(fun accu elt ->
if test elt then elt :: accu else accu)
[] a) in
Array.of_list (List.rev result)
# let _ = filter (fun x -> x mod 2 = 0) [|0; 1; 2; 3; 4; 5|];;
- : int array = [|0; 2; 4|]
Constant stack but O(n) heap.
Jean-Baptiste Rouquier
-------------------
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