Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 527

OCaml map of int keys :: where is the 'simple' int module to use with the Map.Make functor?

$
0
0

I need an OCaml map with keys of type int so I am using Map.Make to create one. However it seems that the standard modules'only' provide modules like Big_int, Int32, Int64 and Nativeint which require conversions. So I have to do things like:

module IntMap = Map.Make(Int32) let a_map = IntMap.add (Int32.of_int 0) "zero" IntMap.empty ;;

... which I would rather avoid or define my own silly Int module do deal with simple int literals or values without requiring conversion functions:

module Int = struct                          type t = int                                                 let compare x y = if x < y then -1 else if x > y then 1 else 0 end ;;  module IntMap = Map.Make(Int) let a_map = IntMap.add 0 "zero" IntMap.empty ;;

Am I missing something obvious here?


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>