caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kenichi Asai <asai@is.ocha.ac.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Labels at the module level?
Date: Wed, 24 Jun 2015 09:25:36 +0900	[thread overview]
Message-ID: <20150624002536.GA5582@pllab.is.ocha.ac.jp> (raw)
In-Reply-To: <20150623082651.GA5301@pllab.is.ocha.ac.jp>

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

  parent reply	other threads:[~2015-06-24  0:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-23  8:26 Kenichi Asai
2015-06-23  8:43 ` Jeremy Yallop
2015-06-23  8:46   ` Benjamin Greenman
2015-06-24  0:25 ` Kenichi Asai [this message]
2015-06-26  8:12   ` Ben Millwood
2015-06-23  8:50 Oleg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150624002536.GA5582@pllab.is.ocha.ac.jp \
    --to=asai@is.ocha.ac.jp \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).