2016-06-01 34 views
1

我使用Core.Std生成一组,并在.ml文件中的地图:OCaml的:形容模块.mli文件

type temp = int with sexp, compare 

type label = Symbol.symbol with sexp, compare 

module Temp = struct 
    type t = temp with sexp, compare 
end 
module TempComp = Comparable.Make(Temp) 
module TempSet = TempComp.Set 
module TempMap = TempComp.Map 

module Label = struct 
    type t = label with sexp, compare 
end 
module LabelComp = Comparable.Make(Label) 
module LabelMap = LabelComp.Map 

我应该如何形容TempSet, TempMap, LabelMap.mli文件?

我把: module TempMap : Map.S with type t = temp

但我得到了一个错误:

In this `with' constraint, the new definition of t does not match its original definition in the constrained signature: Type declarations do not match: type t = t is not included in type 'a t = (Key.t, 'a, Key.comparator_witness) Map.t

我怎样才能解决这个问题?

回答

1

'a t类型是从temp(一键)到'a(任意数据)的一种映射类型。什么你想说的,是'a t从具体类型temp的一个关键的地图,以及这样做的正确的方法是:

module TempMap : Map.S with type Key.t = temp 

然而,虽然它是做事它以正确的方式不是直截了当的,因为它需要你深入地图的签名。常见的方法是只说:

type temp 
module Temp : Comparable with type t = temp 

,让你的界面的用户使用Temp.MapTemp.Set,等等。此外,可以考虑使用更丰富的接口Identifiable,也将包括哈希表,hashsets,以及其它许多有用和期望的东西。