-
-
Save raphael-proust/886595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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