Necesito un mapa OCaml con las claves del tipo int entonces estoy usando Map.Make para crear una. Sin embargo, parece que el standard modules 'sólo' proporcionan módulos como Big_int, Int32, Int64 y Nativeint que requieren conversiones. Así que tengo que hacer cosas como:OCaml map of int keys :: where is the 'simple' int module to use with the Map.Make functor?
module IntMap = Map.Make(Int32)
let a_map = IntMap.add (Int32.of_int 0) "zero" IntMap.empty ;;
... lo que yo preferiría evitar o definir mi propia tonta módulo Int no tratar con simples int literales o valores sin necesidad de funciones de conversión:
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 ;;
¿Me falta algo obvio aquí?
Simplemente use 'Pervasives.compare'. – Ptival