OCaml 缺少标准库函数
OCaml missing standard library functions
我注意到我安装的 OCaml 中缺少一些标准库函数(我按照 Ubuntu here 的说明进行操作)。
例如,如果我输入
#show Hashtbl;;
在 utop
顶层,我得到以下签名
module Hashtbl: sig
type ('a, 'b) t
val create : ?random:bool -> int -> ('a, 'b) t
val clear : ('a, 'b) t -> unit
val reset : ('a, 'b) t -> unit
val copy : ('a, 'b) t -> ('a, 'b) t
val add : ('a, 'b) t -> 'a -> 'b -> unit
val find : ('a, 'b) t -> 'a -> 'b
val find_all : ('a, 'b) t -> 'a -> 'b list
val mem : ('a, 'b) t -> 'a -> bool
val remove : ('a, 'b) t -> 'a -> unit
val replace : ('a, 'b) t -> 'a -> 'b -> unit
val iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit
val fold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c
val length : ('a, 'b) t -> int
val randomize : unit -> unit
type statistics = {
num_bindings : int;
num_buckets : int;
max_bucket_length : int;
bucket_histogram : int array;
}
val stats : ('a, 'b) t -> statistics
module type HashedType =
sig type t val equal : t -> t -> bool val hash : t -> int end
module type S =
sig
type key
type 'a t
val create : int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats : 'a t -> statistics
end
module Make : functor (H : HashedType) -> sig end
module type SeededHashedType =
sig type t val equal : t -> t -> bool val hash : int -> t -> int end
module type SeededS =
sig
type key
type 'a t
val create : ?random:bool -> int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats : 'a t -> statistics
end
module MakeSeeded : functor (H : SeededHashedType) -> sig end
val hash : 'a -> int
val seeded_hash : int -> 'a -> int
val hash_param : int -> int -> 'a -> int
val seeded_hash_param : int -> int -> int -> 'a -> int
end
请注意缺少 Hashtbl.filter_map_inplace
和 Hashtbl.is_randomized
,它们在 online documentation.
中列出
- 为什么签名不同?
- 从哪里获得正确的库(或正确的文档)?
这是一个版本问题。 filter_map_inplace
似乎 released in 4.03, is_randomized
in 4.02. Ubuntu's OCaml package 使用 4.01 版。
您可以使用 Anil Madhavapeddy's PPAs
找到更新的版本
add-apt-repository ppa:avsm/ppa
apt-get update
apt-get install ocaml ocaml-native-compilers camlp4-extra opam
(来自https://opam.ocaml.org/doc/Install.html)
或者一旦你有了 OPAM,你就可以用它来 install a newer version.
opam switch 4.02.1
eval `opam config env`
我注意到我安装的 OCaml 中缺少一些标准库函数(我按照 Ubuntu here 的说明进行操作)。 例如,如果我输入
#show Hashtbl;;
在 utop
顶层,我得到以下签名
module Hashtbl: sig
type ('a, 'b) t
val create : ?random:bool -> int -> ('a, 'b) t
val clear : ('a, 'b) t -> unit
val reset : ('a, 'b) t -> unit
val copy : ('a, 'b) t -> ('a, 'b) t
val add : ('a, 'b) t -> 'a -> 'b -> unit
val find : ('a, 'b) t -> 'a -> 'b
val find_all : ('a, 'b) t -> 'a -> 'b list
val mem : ('a, 'b) t -> 'a -> bool
val remove : ('a, 'b) t -> 'a -> unit
val replace : ('a, 'b) t -> 'a -> 'b -> unit
val iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit
val fold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c
val length : ('a, 'b) t -> int
val randomize : unit -> unit
type statistics = {
num_bindings : int;
num_buckets : int;
max_bucket_length : int;
bucket_histogram : int array;
}
val stats : ('a, 'b) t -> statistics
module type HashedType =
sig type t val equal : t -> t -> bool val hash : t -> int end
module type S =
sig
type key
type 'a t
val create : int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats : 'a t -> statistics
end
module Make : functor (H : HashedType) -> sig end
module type SeededHashedType =
sig type t val equal : t -> t -> bool val hash : int -> t -> int end
module type SeededS =
sig
type key
type 'a t
val create : ?random:bool -> int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats : 'a t -> statistics
end
module MakeSeeded : functor (H : SeededHashedType) -> sig end
val hash : 'a -> int
val seeded_hash : int -> 'a -> int
val hash_param : int -> int -> 'a -> int
val seeded_hash_param : int -> int -> int -> 'a -> int
end
请注意缺少 Hashtbl.filter_map_inplace
和 Hashtbl.is_randomized
,它们在 online documentation.
- 为什么签名不同?
- 从哪里获得正确的库(或正确的文档)?
这是一个版本问题。 filter_map_inplace
似乎 released in 4.03, is_randomized
in 4.02. Ubuntu's OCaml package 使用 4.01 版。
您可以使用 Anil Madhavapeddy's PPAs
找到更新的版本add-apt-repository ppa:avsm/ppa
apt-get update
apt-get install ocaml ocaml-native-compilers camlp4-extra opam
(来自https://opam.ocaml.org/doc/Install.html)
或者一旦你有了 OPAM,你就可以用它来 install a newer version.
opam switch 4.02.1
eval `opam config env`