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...
A module interface expresses the elements that are provided and required by the module. The elements defined in the interface are detectable by other modules. The implementation contains the working code that corresponds to the elements declared in the interface.
Modular design is basically to decompose complex systems into simple modules in order to more efficiently organize complex designs and processes. The concept was first introduced by Star (1965), in which the use of modular product in production was proposed as a new concept to develop variety.
Modular design, or modularity in design, is a design principle that subdivides a system into smaller parts called modules (such as modular process skids), which can be independently created, modified, replaced, or exchanged with other modules or between different systems.
Information hiding modules and abstract interfaces are the basic concepts needed to design multi-version programs.
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);
()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With