How can I find the size of the `map` in ocaml? Am I using the "Map.Make" function to create a module?

I could not find the size or len function in the official documentation. What is an easy way to find the number of elements on a map created with:

module M = Map.Make(String)

I am looking for something like M.size M.empty : 0 .

+7
ocaml
source share
2 answers

The function you are looking for is called cardinal (as in dialing power).

Example:

 module M = Map.Make(String) let m = M.singleton "x" "y" let () = Printf.printf "%d\n" (M.cardinal m) 

This will print 1 , since there is only one binding.

+8
source share
 hoogle4ocaml ": 'at -> int$" | grep -i map 

I will tell you:

 ~/.opam/4.05.0/lib/ocaml/map.mli: val cardinal: 'at -> int 

Cf. https://github.com/UnixJunkie/hoogle_for_ocaml

-one
source share

All Articles