Some functions I could not rewrite using core
David House
dhouse at janestreet.com
Mon Nov 12 07:38:12 GMT 2012
hashtbl_of is called of_alist or of_alist_exn. (Note that because this
is a creator function, you have to either use Foo.Table.of_alist, or
Hashtbl.Poly.of_alist -- see my email last week.)
I don't think we have a function that does reverse_binding (I can't
recall ever needing it). But you should be able to write it using the
other functions in Hashtbl. What precisely are you struggling with?
On Mon, Nov 12, 2012 at 5:49 AM, Francois Berenger
<francois.berenger.working at gmail.com> wrote:
> Hello,
>
> I'm stuck with these (standard OCaml code I'd like t
> make core-compatible, or know the equivalent functions
> in Core):
>
> module A = Array
> module F = Filename
> module HT = Hashtbl
> module L = List
> module Mar = Marshal
> module P = Printf
> module RNG = Random
> module S = String
>
> (* create a Hashtbl from a list of key-value pairs *)
> let hashtbl_of key_value_pairs =
> let res = HT.create (L.length key_value_pairs) in
> L.iter
> (fun (k, v) -> HT.add res k v)
> key_value_pairs;
> res
>
> (* transform a Hashtbl of key->value into a Hashtbl of value->key *)
> let reverse_binding ht =
> let res = HT.create (HT.length ht) in
> HT.iter
> (fun k v -> HT.add res v k)
> ht;
> res
>
> Thanks,
> F.
>
More information about the core
mailing list