From: Ben Millwood <bmillwood@janestreet.com>
To: Kenichi Asai <asai@is.ocha.ac.jp>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Labels at the module level?
Date: Fri, 26 Jun 2015 09:12:19 +0100 [thread overview]
Message-ID: <CA+MHO51PysAOTppyO3qQUk=F-QgUvR4_fu93Qnwc8AnTxinp7g@mail.gmail.com> (raw)
In-Reply-To: <20150624002536.GA5582@pllab.is.ocha.ac.jp>
[-- Attachment #1: Type: text/plain, Size: 2328 bytes --]
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 <asai@is.ocha.ac.jp> 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
>
[-- Attachment #2: Type: text/html, Size: 4149 bytes --]
next prev parent reply other threads:[~2015-06-26 8:12 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
2015-06-26 8:12 ` Ben Millwood [this message]
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='CA+MHO51PysAOTppyO3qQUk=F-QgUvR4_fu93Qnwc8AnTxinp7g@mail.gmail.com' \
--to=bmillwood@janestreet.com \
--cc=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