caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] RFH: type / consistency problem
Date: Mon, 13 May 2013 15:09:11 +0200	[thread overview]
Message-ID: <20130513130911.GJ8366@frosties> (raw)
In-Reply-To: <m49vc6nqduu.fsf@coffee.modeemi.fi>

On Mon, May 13, 2013 at 03:11:05PM +0300, Erkki Seppala wrote:
> Something like this?
> 
> module Protocol : sig
>   type 'a request
>   type 'a reply
>   type session
> 
>   val issue : session -> 'a request -> 'a
> 
>   type foo_response = { fr_s : string }
>   val foo : string -> foo_response request
> 
>   type bar_response = int
>   val bar : int -> bar request
> 
>   type baz_response = unit
>   val baz : unit -> baz request
> end = struct
>   type 'a reply = string -> 'a
>   type 'a request = {
>     req_type : int;
>     req_data : string;
>     req_handle : 'a reply
>   }
> 
>   type foo_response = { fr_s : string }
>   
>   let issue session request =
>     send (request.req_type, request.req_data);
>     request.req_handle (receive ())
> 
>   let foo int = 
>     let handle_foo_response str =
>       { fr_s = str }
>     in
>       { req_type = 42; req_data = Printf.sprintf "hello %d" int;
>         req_handle = handle_foo_response }
> 
>   (* etc *)
> end
> 
> The nice thing about this is that you can support synchronous and
> asynchronous communication with essentially the same interface of
> constructing messages, you just have a different kind of issue function.

There is no connection between the 'a of a request, req_type and the
req_data. req_data isn't even the raw data anymore but, I assume,
already the serialized data ready for sending. So you have gone from 2
independet types to 3. I could create a foo_responce request with
req_type = Bar containing the data for type Buzz.

And what about the server? It reads requests from the network and has
to send out matching replies. I'm actually more interested in that
side, but both should work and have the same common type.

MfG
	Goswin

      reply	other threads:[~2013-05-13 13:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-13  9:40 Goswin von Brederlow
2013-05-13 12:11 ` Erkki Seppala
2013-05-13 13:09   ` Goswin von Brederlow [this message]

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=20130513130911.GJ8366@frosties \
    --to=goswin-v-b@web.de \
    --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).