caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Erkki Seppala <flux-caml@inside.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] RFH: type / consistency problem
Date: Mon, 13 May 2013 15:11:05 +0300	[thread overview]
Message-ID: <m49vc6nqduu.fsf@coffee.modeemi.fi> (raw)
In-Reply-To: <20130513094015.GB8366@frosties> (Goswin von Brederlow's message of "Mon, 13 May 2013 11:40:15 +0200")

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.

-- 
  _____________________________________________________________________
     / __// /__ ____  __               http://www.modeemi.fi/~flux/\   \
    / /_ / // // /\ \/ /                                            \  /
   /_/  /_/ \___/ /_/\_\@modeemi.fi                                  \/

  reply	other threads:[~2013-05-13 12:11 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 [this message]
2013-05-13 13:09   ` Goswin von Brederlow

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=m49vc6nqduu.fsf@coffee.modeemi.fi \
    --to=flux-caml@inside.org \
    --cc=caml-list@yquem.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).