Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 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 ( 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 Archives:
Bug reports: FAQ:
Beginner's list: