7
这里有一个小例子,从我的代码演示问题:值没有足够多态
module Substring = struct
type t = {
base: string;
pos: int;
len: int
}
end
module Parser = struct
type 'a t = Substring.t -> ('a * Substring.t) option
let return x s = Some (x, s)
end
type (_, _) t =
| TryParse : unit Parser.t -> ('a, 'a) t
| Parse : 'b Parser.t -> ('a, 'b -> 'a) t
| Concat : ('b, 'c) t * ('a, 'b) t -> ('a, 'c) t
let p = Parse (Parser.return "xxx")
我的问题是,我想val p : ('a, string -> 'a) t
具有多态性,但OCaml的使'a
弱:val p : ('_a, string -> '_a)
。我很确定我在这里受到价值限制的困扰,我不太清楚如何解决这个问题。