Modules and Interface Design

I would like to define a PROPERTY interface and at least 2 Type and Formula modules corresponding to 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 Type constructors to be called outside (if necessary, all programs)

2) A part of some Formula values ​​contains Types values, for example Fplus (5, Type.Tint) is of type Formula ; also some Formula functions would have to call some functions from Type , for example, Formula.union must call Type.union

Can someone tell me how to amend the declaration above to fill in my requirements? If necessary, additional modules can be added ...

+6
source share
1 answer

Do not apply seal seals : PROPERTY to the module declaration. This hides additional information from the returned module. You should use:

  module Type = struct .. end module Formula = struct .. end 

If you still want to verify that Type and Formula satisfy the PROPERTY interface, you can do this separately:

  let () = ignore (module Type : PROPERTY); ignore (module Formula : PROPERTY); () 
+6
source

All Articles