English 中文(简体)
OCaml地图 在什么地方,使用地图是简单的内联网模块。 ??
原标题:OCaml map of int keys :: where is the simple int module to use with the Map.Make functor?
  • 时间:2012-04-12 21:02:06
  •  标签:
  • ocaml

我需要一个包含以下几类钥匙的OCaml地图:int,因此,我正在使用Map.Make制作。 然而,标准模块仅提供以下模块:Big_int,,Int32,Int64>Nativeint,要求转换。 因此,我必须做如下事情:

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

......我会避免或界定我自己sil的Int模块确实涉及简单的int<>/em>字面或数值,而不需要转换功能:

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 ;;

我在这里没有明显的东西?

最佳回答

绘制地图的最简单方式是:

module IntMap = Map.Make(struct type t = int let compare = compare end)
问题回答

I dont think you re missing anything, there s no standard module for this. I believe the BatInt module of OCaml Batteries Included does what you want.

(为了补充:这是事实,我自己使用托马斯所建议的方法!)

如果您使用<条码>集装箱封存器<>编码>(我想这是自先前的答复撰写以来更为常见的),你可以方便地利用集装箱排入模块以及CCMap模块来做到这一点,例如:

module ByInt = CCMap.Make(CCInt)





相关问题
ocamlc, module compilation

I wrote an app in ocaml. It consist of several modules: Util (util.ml) Work1 (work1.ml) -- open Util Work2 (work2.ml) -- open Util, too Main (main.ml) -- open all of them. When i compile its, using ...

How can I simplify this ocaml pattern-matching code?

I m writing a simple little ocaml program that reads an algebraic statement in from a file, parses it into an AST using ocamllex/ocamlyacc, reduces it, and then prints it. The part where I m reducing ...

How can I create a type with multiple parameters in OCaml?

I m trying to create a type that has multiple type parameters. I know how to make a type with one parameter: type a foo = a * int But I need to have two parameters, so that I can parameterize the ...

Hashtable indexed on several fields

I m currently programming an OCaml module defining a type corresponding to a CPU register. The interface of this module is the following : (* * Defines a type which represents a R3000 register. *) ...

Extending an existing type in OCaml

I ve been doing some OCaml programming lately to learn the language and to get more acquainted with functional programming. Recently, I ve started to think that I d like to be able to extend an ...

Ocaml Syntax Error

What s wrong with this code? I can t figure it out: let parent (rules : grammar) (symbol1 : string) (symbol2 : string) : (SymbolSet.t) = try SymbolSet.singleton (getParent [symbol1; symbol2] ...