(* I would like to reformulate a question that I posted previously to make it clearer and attract more attention... I think the question is still interesting... *)
I have defined a module type ZONE as follows:
(* part of zone.ml *)
module type ZONE =
sig
type info
type prop
type t = { s: string; p: prop; i: info }
val f1 : t -> string
end
where i: info is used to contain various information, which help avoid repeat calculation. It will not be always the same because it is up to the Prop from which a Zone is built. For instance, here is a functor to build a module Zone of type ZONE from a module of type PROP, with a basic info:
(* part of zone.ml *)
module ZoneFun (Prop : PROP) = struct
type info = { a: int }
type prop = Prop.t
type t = { s: string; p: prop; i: info }
let f0 z = "f0"
...
end
Here is another functor to build a module Zone of type ZONE, with a relatively more complicated info:
(* zoneFunPrec.ml *)
module ZoneFunPrec (Prop: PROP) (Prec: ZONESM) = struct
type info = { a: int; b: Prec.t }
type prop = Prop.t
type t = { s: string; p: prop; i: info }
let get_prec z = z.info.prec
let f0 z = "f0"
...
end
Then I can use the functors as follows:
module ZoneC = ZoneFun(PropC)
module ZoneA = ZoneFunPrec(PropA)(ZonesmB)
The problem is that, type info and get_prec (ZoneFun has it, whereas ZoneFunPrec hasn't) are the only differences of these 2 functors; their type prop and type t are same, their functions f0, f1... (there are quite several) are exactly same too.
So I am wondering how to avoid from implementing f0, f1, etc. twice...
Does anyone have an idea of restructuring the modules/functors to achieve this and make them meaningful?
ZoneFun(ProcC), just amended... - SoftTimur