OCaml 标准地图与简街 Core.std 地图
OCaml standard Map vs. Jane Street Core.std Map
所以我在我的程序中使用 Jane Street 的 Core.std 来处理某些事情,但仍然想使用标准的 OCaml 地图。但是,当我调用像 mem 这样的函数时,它需要 Core.std 版本的签名。我如何克服这个障碍?谢谢!
open Core.Std
open Map
module PortTable = Map.Make(String)
let portTable = PortTable.empty
let string_add = (Int64.to_string packet.dlDst) in
PortTable.mem string_add portTable
这不会为我编译,因为它期待 Core.std 版本的 mem,而不是标准版本:
Error: This expression has type string but an expression was expected of type
'a PortTable.t = (string, 'a, PortTable.Key.comparator_witness) t
我只想使用标准版。如果有人能提供帮助,我们将不胜感激。
这是一个建议:
module StdMap = Map
open Core.Std
module PortTable = StdMap.Make(String)
这里有一段 session 展示其工作原理的摘录:
# module PortTable = StdMap.Make(String);;
module PortTable :
sig
type key = Core.Std.String.t
type 'a t = 'a Map.Make(Core.Std.String).t
val empty : 'a t
val is_empty : 'a t -> bool
val mem : key -> 'a t -> bool
...
end
#
请注意,PortTable
是从标准 OCaml Map.Make 仿函数创建的,但 String
是来自 Core 的仿函数。您可以使用类似的技巧来保留标准 OCaml 字符串模块的名称。
(就个人而言,我不会打开 StdMap
模块;命名空间已经很拥挤了。)
Core.Std
库通过 Caml
模块公开标准库,因此,您只需在其名称前加上 Caml.
前缀即可访问标准库中的任何值,例如,
module PortableMap = Caml.Map.Make(String)
所以我在我的程序中使用 Jane Street 的 Core.std 来处理某些事情,但仍然想使用标准的 OCaml 地图。但是,当我调用像 mem 这样的函数时,它需要 Core.std 版本的签名。我如何克服这个障碍?谢谢!
open Core.Std
open Map
module PortTable = Map.Make(String)
let portTable = PortTable.empty
let string_add = (Int64.to_string packet.dlDst) in
PortTable.mem string_add portTable
这不会为我编译,因为它期待 Core.std 版本的 mem,而不是标准版本:
Error: This expression has type string but an expression was expected of type
'a PortTable.t = (string, 'a, PortTable.Key.comparator_witness) t
我只想使用标准版。如果有人能提供帮助,我们将不胜感激。
这是一个建议:
module StdMap = Map
open Core.Std
module PortTable = StdMap.Make(String)
这里有一段 session 展示其工作原理的摘录:
# module PortTable = StdMap.Make(String);;
module PortTable :
sig
type key = Core.Std.String.t
type 'a t = 'a Map.Make(Core.Std.String).t
val empty : 'a t
val is_empty : 'a t -> bool
val mem : key -> 'a t -> bool
...
end
#
请注意,PortTable
是从标准 OCaml Map.Make 仿函数创建的,但 String
是来自 Core 的仿函数。您可以使用类似的技巧来保留标准 OCaml 字符串模块的名称。
(就个人而言,我不会打开 StdMap
模块;命名空间已经很拥挤了。)
Core.Std
库通过 Caml
模块公开标准库,因此,您只需在其名称前加上 Caml.
前缀即可访问标准库中的任何值,例如,
module PortableMap = Caml.Map.Make(String)