Skip to content

Instantly share code, notes, and snippets.

@raphael-proust
Created March 25, 2011 09:17
Show Gist options
  • Save raphael-proust/886595 to your computer and use it in GitHub Desktop.
Save raphael-proust/886595 to your computer and use it in GitHub Desktop.
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 =
sig
include Message
val dispatch : request_variant -> obj
end
module type REPLY_FUNCTOR = functor (Req : REQUEST) ->
struct
module Rep : REPLY
module Req : REQUEST
end
module Server (Rep_func : REPLY_FUNCTOR) (Req : REQUEST) =
struct
module M = Rep_func (Req)
let server =
while true do
let req = M.Req.make () in
let var = M.Req.convert req in
let rep = M.Rep.dispatch var in
M.Req.print req;
M.Rep.print rep
done
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment