Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Joel Reymont <joelr1@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] Re: module typing issue
Date: Fri, 25 Mar 2011 14:17:55 +0000	[thread overview]
Message-ID: <639CCD2C-402F-4754-B942-B460FD908A95@gmail.com> (raw)
In-Reply-To: <C2959F12-C0AA-49F2-931F-3BEAD90493A9@gmail.com>

It appears that I spoke to early as I'm still having trouble with the implementation of my concept. 

What is it?

I'm working with ZeroMQ and Thrift. The latter generates messages using OCaml classes. 

I have request and reply messages in my system and replies are created (dispatched) based on their request pair.

A server should not have to know what messages it's dealing with.

I would like to wrap each message class in a variant, particularly helpful since some message classes are unions in the original Thrift DSL but the Thrift OCaml code generator implements them poorly.

Is my intent clear in the code below and if so how do I make it work?

	Thanks, Joel

--- error

File "x.ml", line 56, characters 26-35:
Error: Signature mismatch:
       Modules do not match:
         sig
           type obj = MyRequest.obj
           type variant = MyRequest.variant = A
           val make : unit -> int
           val convert : 'a -> variant
           val print : 'a -> unit
         end
       is not included in
         Request
       Values do not match:
         val make : unit -> int
       is not included in
         val make : unit -> obj

--- x.ml

module type Message = 
sig 
  type obj 
  type variant
  val make : unit -> obj
  (* encapsulate object in a variant type *)
  val convert : obj -> variant
  val print : obj -> unit
end

module type Request = 
sig 
  include Message
end

(* dispatches based on a request *)

module type Reply = functor (Req : Request) ->
sig 
  include Message
  val dispatch : Req.variant -> obj
end

module Server (Req : Request) (REP : Reply) =
struct 
  module Rep = REP(Req)
  let server = 
    while true do
      let req = Req.make () in
      let var = Req.convert req in
      let rep = Rep.dispatch var in
      Req.print req;
      Rep.print rep
    done
end

module MyRequest =
struct
  type obj = private int
  type variant = A
  let make () = 1
  let convert o = A
  let print o = ()
end

module MyReply = functor (Req: Request) ->
struct
  type obj = private int
  type variant = B
  let make () = 2
  let convert o = B
  let print o = ()
  let dispatch _ = B
end

module MyServer = Server (MyRequest) (MyReply)

--------------------------------------------------------------------------
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------





  reply	other threads:[~2011-03-25 14:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-25  8:34 [Caml-list] " Joel Reymont
2011-03-25  8:44 ` [Caml-list] " Joel Reymont
2011-03-25 14:17   ` Joel Reymont [this message]
2011-03-25 15:46     ` Andreas Rossberg
2011-03-25 15:57       ` Joel Reymont
2011-03-25 16:04         ` Andreas Rossberg
2011-03-25 16:42       ` Guillaume Yziquel
2011-03-25 16:59         ` Andreas Rossberg
2011-03-25 19:01           ` Guillaume Yziquel
2011-03-25 19:13             ` Andreas Rossberg
2011-03-28  7:53             ` Alain Frisch
2011-03-28 10:33               ` Guillaume Yziquel
2011-03-28 11:29                 ` David Allsopp
2011-03-28 11:58                   ` Guillaume Yziquel
2011-03-28 12:11                     ` David Allsopp
2011-03-28 12:29                       ` Guillaume Yziquel
2011-03-28 12:23                     ` Alain Frisch
2011-03-28 12:39                       ` Guillaume Yziquel
2011-03-28 11:32               ` David Allsopp
2011-03-28 12:02                 ` Guillaume Yziquel

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=639CCD2C-402F-4754-B942-B460FD908A95@gmail.com \
    --to=joelr1@gmail.com \
    --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