が、私はこれらのシグネチャがあるとします。パラメータ化されたファンクタ
module type CharS = sig
type c
type t = BoW | C of c | EoW
val compare : t -> t -> int
val print : Format.formatter -> t -> unit
end
module type GraphemS = sig
type c
type t
val compare : t -> t -> int
val print : Format.formatter -> t -> unit
end
そして、これら二つのファンクタ:
今module MakeDiGraphem (C : CharS) : GraphemS with type c = C.t = struct
type c = C.t
type t = c * c
let compare (cb1, ce1) (cb2, ce2) =
let r1 = C.compare cb1 cb2 in
if r1 = 0 then
C.compare ce1 ce2
else r1
let print fmt (cb, ce) =
Format.fprintf fmt "@[%a%[email protected]]@," C.print cb C.print ce
end
module MakeMonoGraphem (C : CharS) : GraphemS with type c = C.t = struct
type c = C.t
type t = c
let compare c1 c2 = C.compare c1 c2
let print fmt c =
Format.fprintf fmt "@[%[email protected]]@," C.print c
end
、私は私がタイプのモジュールを作成できるようになるファンクタをしたいのですが最初のファンクタか2番目のファンクタを持つGraphemS。
module type SizeS = sig
type t = int
val param : int
end
module MakeGraphem (C : CharS) (I : SizeS) : GraphemS with type c = C.t = struct
module MonoGraphem = MakeMonoGraphem(C)
module DiGraphem = MakeDiGraphem(C)
let select_graphem =
if I.param = 1 then
(module MonoGraphem : GraphemS)
else
(module DiGraphem : GraphemS)
include (val select_graphem)
end
しかし、悲しいことに、私が得た:私がやったことはこれです
Error: This expression creates fresh types.
It is not allowed inside applicative functors.
私の質問は、それから、それは私がやりたいと何このエラーは意味ないすることは可能ですか?
ご返信いただきまして申し訳ありません。署名に問題が多かったため、私はそれを機能させようとしていました。私はファンクタを引数として使用しました(私はそれをやりたいと思いましたが、それは可能ではないと考えていましたので、この "パラメータ"で私のチートです)。 – Lhooq