Instead of having Client and Server depend on Message, consider having Check_message_types depend on both Client and Server, and in check_message_types.ml you have: let check_message_types_are_equal (x : Client.t) : Server.t = x On 24 June 2015 at 01:25, Kenichi Asai wrote: > Thanks for all the answers! Let me ask one more (somewhat related) > question. I want to share a type of messages between a client and a > server (in communicating games students write to avoid segmentation > fault caused by marshaling or a runtime error caused by bin-prot). > One natural way to do it is to have a file message.ml: > > message.ml: > ----- > type t = int * int (* example type of messages *) > ----- > > and use it in both the client and the server: > > client.ml: > ----- > let send (message : Message.t) = > ... marshal the message and send to the server ... > ----- > > server.ml: > ----- > let receive () : Message.t = > ... unmarshal the message received from the client ... > ----- > > In this case, however, students always have to write message.ml and > declare Message.t even if it can be automatically inferred from the > code of client.ml and server.ml. Ideally, I want to provide > message.ml something like: > > message.ml: > ----- > type t = '_a > ----- > > which signifies that the type Message.t can be anything as long as it > is instantiated to exactly one type throughout the program (i.e., both > in the client and the server). Students could then write only > client.ml and server.ml. If they instantiate Message.t consistently, > the program compiles fine; otherwise, compilation leads to a type error. > > Because the above definition of message.ml is not allowed, I defined: > > message.ml: > ----- > type t = int (* dummy type *) > ----- > > and tried to override it: > > client.ml: > ----- > include Message > type t = int * int > ----- > > but it doesn't work. Would there be any way to impose a constraint > that two types in two different modules to be the same without > specifying the type itself? > > Sincerely, > > -- > Kenichi Asai > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >