Reputation: 5540
I would like to define an interface PROPERTY
, and at least 2 modules Type
and Formula
matching it:
module type PROPERTY =
sig
type t
val top : t
val bot : t
val to_string: t -> string
val union: t -> t -> t
val intersection: t -> t -> t
end
module Type = (struct
type t =
| Tbot
| Tint
| Tbool
| Ttop
...
end: PROPERTY)
module Formula = (struct
type t =
| Fbot
| Ftop
| Fplus of int * Type.t
...
let union =
... Type.union ...
...
end: PROPERTY)
There are two requirements:
1) I would like the constructors of Type
can be called outside (all the programs if necessary)
2) A part of some values of Formula
contain values of Types
, for instance Fplus (5, Type.Tint)
is of type Formula
; also some functions of Formula
would need to call some functions of Type
, for example, Formula.union
needs to call Type.union
Could anyone tell me how to amend the declaration above to fullfil my requirements? Extra modules can be added if necessary...
Upvotes: 6
Views: 127
Reputation: 31469
Don't apply the : PROPERTY
sealing casts to the module declaration. This hides the extra information from the returned module. You should rather use:
module Type = struct .. end
module Formula = struct .. end
If you still want to check that Type
and Formula
do satisfy the PROPERTY
interface, you can do that separately:
let () =
ignore (module Type : PROPERTY);
ignore (module Formula : PROPERTY);
()
Upvotes: 6