【发布时间】:2019-12-07 23:43:13
【问题描述】:
我正在阅读Real World Ocaml 中有关共享约束的信息,但无法通过更改模块类型签名来了解有关公开endpoint 工作的部分。
open Core
module type Interval_intf = sig
type t
type endpoint
val create : endpoint -> endpoint -> t
val is_empty : t -> bool
val contains : t -> endpoint -> bool
val intersect : t -> t -> t
end
module Make_interval(Endpoint: Comparable): Interval_intf = struct
type endpoint = Endpoint.t
type t =
| Interval of Endpoint.t * Endpoint.t
| Empty
let create low high =
if Endpoint.compare low high > 0 then Empty
else Interval (low, high)
let is_empty = function
| Empty -> true
| Interval _ -> false
let contains t x =
match t with
| Empty -> false
| Interval (l, h) -> Endpoint.compare x l >= 0 && Endpoint.compare x h <= 0
let intersect t1 t2 =
let min x y = if Endpoint.compare x y <= 0 then x else y in
let max x y = if Endpoint.compare x y >= 0 then x else y in
match t1, t2 with
| Empty, _ | _, Empty -> Empty
| Interval (l1, h1), Interval (l2, h2) -> create (max l1 l2) (min h1 h2)
end
module Int_interval_intf : (Interval_intf with type endpoint = int) = Make_interval(Int)
这给出了一个错误:
Error: Signature mismatch:
...
Type declarations do not match:
type endpoint = Make_interval(Core_kernel__Int).endpoint
is not included in
type endpoint = int
这里有什么问题?
这是带有 OCaml 4.06.0 和 Core v0.11.3 的。
【问题讨论】:
标签: ocaml