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)
。我很確定我在這裏受到價值限制的困擾,我不太清楚如何解決這個問題。