Associative-stuff, ocaml api

I’m trying to do some associative stuff.
But there are different types possible.

  1. association-lists
  2. maps
  3. hash-tables
  4. associative-arrays
    What are the ocaml API’s to do this ?
    I know there is Jane-Streeth, but it looks a waste of time. Because you need a community to go somewhere.

Hi, modules for all of the above are in the OCaml standard library. Have you tried there?

  • Association lists
  • Maps (to create a map module for a specific type for which there exists a total ordering comparison function, you have to use the functor Map.Make, whose output signature provides the typical functions for working with maps)
  • Hash tables (side-effectful interface)
  • Associative arrays—maps are associative arrays

What does that even mean?

Jane Street base has a convenient List.Assoc module to deal with association list. That’s often the most convienient way to interop with a lot of associative APIs since that’s what libraries like e.g. Yojson return.

Maps vs Hashtables is a question of whether you want the data structure to be mutable or not. There’s cases for both, but most of the time I would go with a map, especially if returning some data to a consumer. For the common case that the key is a string, Base has String.Map and String.Table so you don’t need to write your own functor, which is somewhat conventient.


If you are interested to associate string with something, you should take look on art which has better performances than Hashtbl :slight_smile: