Version française
Home     About     Download     Resources     Contact us    
Browse thread
polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <mottl@m...>
Subject: Re: polymorphic variants
On Fri, 09 Jun 2000, David Chemouil wrote:
> The problem is that, as server communicate for admistrative reasons,
> they exchange messages with arguments of which I already know the type
> constructor. 
> 
> As a consequence, the servers must manipulate a type 'argument' which is
> not yet completely defined: the part interesting the servers is defined
> but not the one interesting the generated OCaml program. 

Maybe you would want to try something like this (uses the Marshal module):

  type admin_args = ...
  type user_data = string
  type argument = MsgA of admin_args * user_data | MsgB of ... | ...

Then you can react to messages as follows, for example:

  let recv = function
    | MsgA (adm_args, user_data) ->
        handle_adm_args adm_args;
        call_user_program (Marshal.from_string user_data)
    | MsgB ... ->
    ...

Sending would be something like:

  let send user_data =
    let adm_args = create_args ()
    and contents = Marshal.to_string user_data [Closures] in
    send_network (MsgA (adm_args, contents))

Very rudimentary, but the basic idea (keep user data encoded in a string
until needed) should be clear...

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl