Re: polymorphic variants

From: Markus Mottl (mottl@miss.wu-wien.ac.at)
Date: Fri Jun 09 2000 - 22:03:43 MET DST

  • Next message: Julian Assange: "irc.ocaml.org"

    Followup to my last mail:

    Actually, you need not necessarily double decode things (first the network
    message, then the user data): you can do this in one step, too, also using
    the Marshal-module.

    It does not matter whether you know the internals of the user data or not
    (when the type is abstract): the Marshal-module will always do the right
    thing during decoding - but make sure that you only pass on the user data
    to functions of the right type (i.e. ones that can really handle it),
    otherwise your program will crash.

    E.g. (recv takes the raw string from the network now):

      type admin_args = ...
      type user_data (* abstract *)

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

      let recv network_data =
        let msg : argument = Marshal.from_string network_data 0 in
        match msg with
        | MsgA (admin_args, user_data) ->
            handle_admin_args admin_args;
            call_user_program user_data
        | ...
        ...

    Best regards,
    Markus Mottl

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



    This archive was generated by hypermail 2b29 : Mon Jun 12 2000 - 16:05:44 MET DST